Skip to content

Commit 2558ec7

Browse files
authored
Make directory containing secrets configurable (#16)
1 parent b96f7a7 commit 2558ec7

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

main.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"net/http"
2525
"net/url"
2626
"os"
27+
"path"
2728
"strconv"
2829
"time"
2930

@@ -39,6 +40,7 @@ var (
3940
localityZone = flag.String("locality-zone", "", "the locality zone to use, instead of retrieving it from the metadata server. Useful when not running on GCP and/or for testing")
4041
includeV3Features = flag.Bool("include-v3-features-experimental", true, "whether or not to generate configs which works with the xDS v3 implementation in TD. This flag is EXPERIMENTAL and may be changed or removed in a later release.")
4142
includePSMSecurity = flag.Bool("include-psm-security-experimental", false, "whether or not to generate config required for PSM security. This flag is EXPERIMENTAL and may be changed or removed in a later release.")
43+
secretsDir = flag.String("secrets-dir-experimental", "/var/run/secrets/workload-spiffe-credentials", "path to a directory containing TLS certificates and keys required for PSM security. Used only if --include-psm-security-experimental is set. This flag is EXPERIMENTAL and may be changed or removed in a later release.")
4244
)
4345

4446
func main() {
@@ -76,6 +78,7 @@ func main() {
7678
zone: zone,
7779
includeV3Features: *includeV3Features,
7880
includePSMSecurity: *includePSMSecurity,
81+
secretsDir: *secretsDir,
7982
metadataLabels: nodeMetadata,
8083
})
8184
if err != nil {
@@ -117,6 +120,7 @@ type configInput struct {
117120
zone string
118121
includeV3Features bool
119122
includePSMSecurity bool
123+
secretsDir string
120124
metadataLabels map[string]string
121125
}
122126

@@ -161,9 +165,9 @@ func generate(in configInput) ([]byte, error) {
161165
"google_cloud_private_spiffe": {
162166
PluginName: "file_watcher",
163167
Config: privateSPIFFEConfig{
164-
CertificateFile: "/var/run/gke-spiffe/certs/certificates.pem",
165-
PrivateKeyFile: "/var/run/gke-spiffe/certs/private_key.pem",
166-
CACertificateFile: "/var/run/gke-spiffe/certs/ca_certificates.pem",
168+
CertificateFile: path.Join(in.secretsDir, "certificates.pem"),
169+
PrivateKeyFile: path.Join(in.secretsDir, "private_key.pem"),
170+
CACertificateFile: path.Join(in.secretsDir, "ca_certificates.pem"),
167171
// The file_watcher plugin will parse this a Duration proto, but it is totally
168172
// fine to just emit a string here.
169173
RefreshInterval: "600s",

main_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ func TestGenerate(t *testing.T) {
117117
zone: "uscentral-5",
118118
includeV3Features: true,
119119
includePSMSecurity: true,
120+
secretsDir: "/secrets/dir/",
120121
},
121122
wantOutput: `{
122123
"xds_servers": [
@@ -148,9 +149,9 @@ func TestGenerate(t *testing.T) {
148149
"google_cloud_private_spiffe": {
149150
"plugin_name": "file_watcher",
150151
"config": {
151-
"certificate_file": "/var/run/gke-spiffe/certs/certificates.pem",
152-
"private_key_file": "/var/run/gke-spiffe/certs/private_key.pem",
153-
"ca_certificate_file": "/var/run/gke-spiffe/certs/ca_certificates.pem",
152+
"certificate_file": "/secrets/dir/certificates.pem",
153+
"private_key_file": "/secrets/dir/private_key.pem",
154+
"ca_certificate_file": "/secrets/dir/ca_certificates.pem",
154155
"refresh_interval": "600s"
155156
}
156157
}

0 commit comments

Comments
 (0)