Skip to content

Commit 0b311f4

Browse files
authored
Merge pull request #467 from jetstack/venafiCloudFlags
Allow to use ClientID and PrivateKeyPath as flags instead of credentials.json file
2 parents 55bd887 + 4ed7616 commit 0b311f4

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

cmd/agent.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,21 @@ func init() {
8181
"venafi-cloud",
8282
"",
8383
false,
84-
"Runs agent with parsing config and credentials file in Venafi Cloud format if true.",
84+
"Runs agent with parsing config (and credentials file if provided) in Venafi Cloud format if true.",
85+
)
86+
agentCmd.PersistentFlags().StringVarP(
87+
&agent.ClientID,
88+
"client-id",
89+
"",
90+
"",
91+
"Venafi Cloud Service Account client ID. If you use this flag you don't need to use --venafi-cloud as it will assume you are authenticating against Venafi Cloud. Using this removes the need to use a credentials file with Venafi Cloud mode.",
92+
)
93+
agentCmd.PersistentFlags().StringVarP(
94+
&agent.PrivateKeyPath,
95+
"private-key-path",
96+
"",
97+
"/etc/venafi/agent/key/privatekey.pem",
98+
"Venafi Cloud Service Account private key path.",
8599
)
86100
agentCmd.PersistentFlags().BoolVarP(
87101
&agent.OneShot,

pkg/agent/run.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"errors"
77
"fmt"
8+
"io"
89
"io/ioutil"
910
"log"
1011
"net/http"
@@ -39,6 +40,12 @@ var OneShot bool
3940
// VenafiCloudMode flag determines which format to load for config and credential type
4041
var VenafiCloudMode bool
4142

43+
// ClientID is the clientID in case of Venafi Cloud mode
44+
var ClientID string
45+
46+
// PrivateKeyPath is the path for the service account private key in case of Venafi Cloud mode
47+
var PrivateKeyPath string
48+
4249
// CredentialsPath is where the agent will try to loads the credentials. (Experimental)
4350
var CredentialsPath string
4451

@@ -198,6 +205,11 @@ func getConfiguration() (Config, client.Client) {
198205
log.Fatalf("Failed to read config file: %s", err)
199206
}
200207

208+
// If the ClientID of the service account is specified, then assume we are in Venafi Cloud mode.
209+
if ClientID != "" {
210+
VenafiCloudMode = true
211+
}
212+
201213
config, err := ParseConfig(b, VenafiCloudMode)
202214
if err != nil {
203215
log.Fatalf("Failed to parse config file: %s", err)
@@ -225,14 +237,19 @@ func getConfiguration() (Config, client.Client) {
225237
log.Printf("Loaded config: \n%s", dump)
226238

227239
var credentials client.Credentials
228-
if CredentialsPath != "" {
240+
if ClientID != "" {
241+
credentials = &client.VenafiSvcAccountCredentials{
242+
ClientID: ClientID,
243+
PrivateKeyFile: PrivateKeyPath,
244+
}
245+
} else if CredentialsPath != "" {
229246
file, err = os.Open(CredentialsPath)
230247
if err != nil {
231248
log.Fatalf("Failed to load credentials from file %s", CredentialsPath)
232249
}
233250
defer file.Close()
234251

235-
b, err = ioutil.ReadAll(file)
252+
b, err = io.ReadAll(file)
236253
if err != nil {
237254
log.Fatalf("Failed to read credentials file: %v", err)
238255
}

0 commit comments

Comments
 (0)