Skip to content

Commit 13f5240

Browse files
committed
Allow specification of client_id by env var
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 <[email protected]>
1 parent 1f00f09 commit 13f5240

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

pkg/agent/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,10 @@ func InitAgentCmdFlags(c *cobra.Command, cfg *AgentCmdFlags) {
201201
&cfg.ClientID,
202202
"client-id",
203203
"",
204-
"",
204+
os.Getenv("CLIENT_ID"),
205205
fmt.Sprintf("Turns on the %s mode. If you use this flag you don't need to use --venafi-cloud "+
206206
"as it will assume you are authenticating with Venafi Cloud. Using this removes the need to use a "+
207-
"credentials file.", VenafiCloudKeypair),
207+
"credentials file. Defaults to the value of the env var CLIENT_ID", VenafiCloudKeypair),
208208
)
209209
c.PersistentFlags().StringVarP(
210210
&cfg.PrivateKeyPath,

pkg/agent/config_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,21 @@ func Test_ValidateAndCombineConfig(t *testing.T) {
312312
assert.IsType(t, &client.VenafiCloudClient{}, cl)
313313
})
314314

315+
t.Run("venafi-cloud-keypair-auth: authenticated if CLIENT_ID set", func(t *testing.T) {
316+
t.Setenv("POD_NAMESPACE", "venafi")
317+
t.Setenv("CLIENT_ID", "test-client-id")
318+
path := withFile(t, fakePrivKeyPEM)
319+
_, cl, err := ValidateAndCombineConfig(discardLogs(),
320+
withConfig(testutil.Undent(`
321+
cluster_id: foo
322+
venafi-cloud:
323+
upload_path: /foo/bar
324+
`)),
325+
withCmdLineFlags("--venafi-cloud", "--period", "1m", "--private-key-path", path))
326+
require.NoError(t, err)
327+
assert.IsType(t, &client.VenafiCloudClient{}, cl)
328+
})
329+
315330
t.Run("venafi-cloud-keypair-auth: valid 1: --client-id and --private-key-path", func(t *testing.T) {
316331
t.Setenv("POD_NAMESPACE", "venafi")
317332
path := withFile(t, fakePrivKeyPEM)

0 commit comments

Comments
 (0)