Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specification of client_id by env var #608

Closed
wants to merge 1 commit into from
Closed

Conversation

aidy
Copy link

@aidy aidy commented Nov 6, 2024

Specifying client_id by env var allows us to pre-populate a namespace with all the relevant authentication details.

Currently, we have to populate a secret with a private key, and then create a deployment given the client id. Specifying via an env var would allow us to create/rotate deployments and credentials independently of each other.

e.g.

env:
 - name: CLIENT_ID
   valueFrom:
     configMapKeyRef:
       name: venafi-agent-svc-account
       key: client_id

Specifying client_id by env var allows us to pre-populate a namespace
with all the relevant authentication details.

Currently, we have to populate a secret with a private key, and then
create a deployment given the client id. Specifying via an env var would
allow us to create/rotate deployments and credentials independently of each
other.

e.g.

```
env:
 - name: CLIENT_ID
   valueFrom:
     configMapKeyRef:
       name: venafi-agent-svc-account
       key: client_id
```

Signed-off-by: Adrian Lai <adrian.lai@jetstack.io>
@aidy aidy requested a review from maelvls November 6, 2024 18:17
@wallrj
Copy link
Member

wallrj commented Nov 8, 2024

@aidy I don't think it's well documented, but you can set the defaults for all the command line flags using PREFLIGHT_ environment variables. E.g.

PREFLIGHT_INSTALL_NAMESPACE=venafi \
PREFLIGHT_CLIENT_ID=foo \
PREFLIGHT_PRIVATE_KEY_PATH=/dev/null \
./preflight agent
I1108 09:13:21.387671  341204 run.go:57] "Starting" logger="Run" version="development" commit=""
I1108 09:13:21.389308  341204 config.go:395] "Using the Venafi Cloud Key Pair Service Account auth mode since --client-id and --private-key-path were specified." logger="Run"
I1108 09:13:21.389392  341204 config.go:479] "ignoring the venafi-cloud.uploader_id field in the config file. This field is not needed in Venafi Cloud Key Pair Service Account mode." logger="Run"
I1108 09:13:21.389408  341204 config.go:531] "Using period from config" logger="Run" period="1m0s"
I1108 09:13:21.389454  341204 config.go:737] "Loading upload_path from \"venafi-cloud\" configuration." logger="Run"
E1108 09:13:21.389576  341204 root.go:53] "Exiting due to error" err=<
        While evaluating configuration: validating creds: failed loading config using the Venafi Cloud Key Pair Service Account mode: 1 error occurred:
                * while parsing private key file: while decoding the PEM-encoded private key /dev/null, its content were:

 > exit-code=1

Does that solve your problem?

See

func setFlagsFromEnv(prefix string, fs *pflag.FlagSet) {
set := map[string]bool{}
fs.Visit(func(f *pflag.Flag) {
set[f.Name] = true
})
fs.VisitAll(func(f *pflag.Flag) {
// ignore flags set from the commandline
if set[f.Name] {
return
}
// remove trailing _ to reduce common errors with the prefix, i.e. people setting it to MY_PROG_
cleanPrefix := strings.TrimSuffix(prefix, "_")
name := fmt.Sprintf("%s_%s", cleanPrefix, strings.Replace(strings.ToUpper(f.Name), "-", "_", -1))
if e, ok := os.LookupEnv(name); ok {
_ = f.Value.Set(e)
}
})
}

@maelvls
Copy link
Member

maelvls commented Nov 14, 2024

I wasn't aware of these env variable either. Thanks for pointing them out, Richard. @aidy Does PREFLIGHT_CLIENT_ID satisfy your needs?

(We should somehow have these env vars documented somewhere, though)

@maelvls
Copy link
Member

maelvls commented Dec 9, 2024

Hey, I'll close this PR for now.

@aidy let me know if you want to re-open it 👍

@maelvls maelvls closed this Dec 9, 2024
@maelvls maelvls deleted the client_id_env branch December 9, 2024 09:34
@maelvls maelvls restored the client_id_env branch December 9, 2024 09:34
@wallrj wallrj deleted the client_id_env branch December 10, 2024 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants