Register: add --token-file flag #362

Open
Ninjatrappeur wants to merge 4 commits from Ninjatrappeur/nin/token-file into main
pull from: Ninjatrappeur/nin/token-file
Ninjatrappeur commented 2023-09-25 12:00:40 +00:00 (Migrated from gitea.com)

Hey!

At the moment, the only way to pass the secret Gitea token to the
runner CLI is directly through a CLI parameter. That's an issue on a
multi-user system where the CLI parameters are world-readable through
/proc/PID/cmdline. On a Linux system, there's sadly no way to hide the
cmdline parameters.

We usually go around this limitation by storing the secrets in a file
and protect it through tight ACL rules. Adding a way to inject the
secret token via a file during the register command.

As a nice side-effect, this improves the systemd integration by
allowing us to directly use the LoadCredential mechanism.

Some more context: I'm using this new flag on my NixOS personal setup with this Nixpkgs patch: https://github.com/NinjaTrappeur/nixpkgs/commit/0fe31acd33182de1d06ae164d0cc62e6514c5a03

I'll upstream this Nixpkgs patch on the next release -- provided you find this pull request idea sound.

Hey! ``` At the moment, the only way to pass the secret Gitea token to the runner CLI is directly through a CLI parameter. That's an issue on a multi-user system where the CLI parameters are world-readable through /proc/PID/cmdline. On a Linux system, there's sadly no way to hide the cmdline parameters. We usually go around this limitation by storing the secrets in a file and protect it through tight ACL rules. Adding a way to inject the secret token via a file during the register command. As a nice side-effect, this improves the systemd integration by allowing us to directly use the LoadCredential mechanism. ``` Some more context: I'm using this new flag on my NixOS personal setup with this Nixpkgs patch: https://github.com/NinjaTrappeur/nixpkgs/commit/0fe31acd33182de1d06ae164d0cc62e6514c5a03 I'll upstream this Nixpkgs patch on the next release -- provided you find this pull request idea sound.
wolfogre (Migrated from gitea.com) reviewed 2023-09-26 13:10:06 +00:00
techknowlogick (Migrated from gitea.com) approved these changes 2023-10-15 23:20:36 +00:00
techknowlogick commented 2023-10-15 23:20:58 +00:00 (Migrated from gitea.com)

Thanks for the PR!

Thanks for the PR!
techknowlogick (Migrated from gitea.com) reviewed 2023-10-15 23:29:30 +00:00
@@ -256,0 +262,4 @@
token_bytes, err := os.ReadFile(regArgs.TokenFile)
if err != nil {
return fmt.Errorf("Cannot read the token file: %s", regArgs.TokenFile, err)
}
techknowlogick (Migrated from gitea.com) commented 2023-10-15 23:29:30 +00:00

This line is causing build to fail. I’m just making a note of it so I can update it when not on mobile.

This line is causing build to fail. I’m just making a note of it so I can update it when not on mobile.
Tharre commented 2024-09-11 20:44:09 +00:00 (Migrated from gitea.com)

Friendly bump. This is an easy change with a large security benefit.

Friendly bump. This is an easy change with a large security benefit.
lunny commented 2024-09-15 21:21:19 +00:00 (Migrated from gitea.com)

internal/app/cmd/register.go:264:11: fmt.Errorf call needs 1 arg but has 2 args

`internal/app/cmd/register.go:264:11: fmt.Errorf call needs 1 arg but has 2 args`
You are not authorized to merge this pull request.
This pull request can be merged automatically.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin Ninjatrappeur/nin/token-file:Ninjatrappeur/nin/token-file
git checkout Ninjatrappeur/nin/token-file
Sign in to join this conversation.