Skip to content

Commit 635bd0f

Browse files
authored
Merge branch 'tektoncd:main' into main
2 parents 7097e28 + 6e288c1 commit 635bd0f

File tree

5 files changed

+23
-28
lines changed

5 files changed

+23
-28
lines changed

docs/config.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,16 @@ chains.tekton.dev/transparency-upload: "true"
145145
| :-------------------------------- | :------------------------------------------------------------------------------------------ | :--------------- | :------ |
146146
| `signers.kms.auth.address` | URI of KMS server (e.g. the value of `VAULT_ADDR`) | |
147147
| `signers.kms.auth.token` | Auth token KMS server (e.g. the value of `VAULT_TOKEN`) | |
148-
| `signers.kms.auth.token-dir` | Path to store KMS server Auth token (e.g. `/etc/kms-secrets`) | |
148+
| `signers.kms.auth.token-path` | Path to store KMS server Auth token (e.g. `/etc/kms-secrets`) | |
149149
| `signers.kms.auth.oidc.path` | Path used for OIDC authentication (e.g. `jwt` for Vault) | |
150150
| `signers.kms.auth.oidc.role` | Role used for OIDC authentication | |
151151
| `signers.kms.auth.spire.sock` | URI of the Spire socket used for KMS token (e.g. `unix:///tmp/spire-agent/public/api.sock`) | |
152152
| `signers.kms.auth.spire.audience` | Audience for requesting a SVID from Spire | |
153+
153154
> NOTE:
154155
>
155-
> If `signers.kms.auth.token-dir` is set, create a secret with the key `KMS_AUTH_TOKEN` and ensure the Chains deployment mounts this secret to
156-
> the path specified by `signers.kms.auth.token-dir`.
156+
> If `signers.kms.auth.token-path` is set, create a secret and ensure the Chains deployment mounts this secret to
157+
> the path specified by `signers.kms.auth.token-path`.
157158

158159
> [!IMPORTANT]
159160
> To project the latest token values without needing to recreate the pod, avoid using `subPath` in volume mount.

docs/signing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ For Azure, this should have the structure of `azurekms://[VAULT_NAME][VAULT_URL]
7474

7575
Most likely, you will need to set up some additional authentication so that the `chains-controller` deployment has access to your KMS service for signing.
7676

77-
For Vault, if you use Token-based authentication, store the token as a secret with the key name `KMS_AUTH_TOKEN`. Mount this secret to a specific path within the tekton-chains-controller container. Specify the mounted path as the value for the `chains-config` config map key `signers.kms.auth.token-dir`. This approach can also be applied to other KMS providers that support token-based authentication. Note that the existing configuration option `signers.kms.auth.token` will still work. If both values are set, `signers.kms.auth.token-dir` will take precedence.
77+
For Vault, if you use Token-based authentication, store the token as a secret. Mount this secret to a specific path within the tekton-chains-controller container. Specify the mounted path as the value for the `chains-config` config map key `signers.kms.auth.token-path`. This approach can also be applied to other KMS providers that support token-based authentication. Note that the existing configuration option `signers.kms.auth.token` will still work. If both values are set, `signers.kms.auth.token-path` will take precedence.
7878

7979
For GCP/GKE, we suggest enabling [Workload Identity](https://cloud.google.com/kubernetes-engine/docs/how-to/workload-identity), and giving your service account `Cloud KMS Admin` permissions.
8080
Other Service Account techniques would work as well.

pkg/chains/signing/kms/kms.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"net"
2222
"net/url"
2323
"os"
24-
"path/filepath"
2524
"strings"
2625
"time"
2726

@@ -108,8 +107,8 @@ func NewSigner(ctx context.Context, cfg config.KMSSigner) (*Signer, error) {
108107
// as direct value set from signers.kms.auth.token.
109108
// If both values are set, priority will be given to token-dir.
110109

111-
if cfg.Auth.TokenDir != "" {
112-
rpcAuthToken, err := getKMSAuthToken(cfg.Auth.TokenDir)
110+
if cfg.Auth.TokenPath != "" {
111+
rpcAuthToken, err := getKMSAuthToken(cfg.Auth.TokenPath)
113112
if err != nil {
114113
return nil, err
115114
}
@@ -138,15 +137,10 @@ func NewSigner(ctx context.Context, cfg config.KMSSigner) (*Signer, error) {
138137
}
139138

140139
// getKMSAuthToken retreives token from the given mount path
141-
func getKMSAuthToken(dir string) (string, error) {
142-
tokenEnv := "KMS_AUTH_TOKEN" // #nosec G101
143-
144-
// Cocatenate secret mount path specified in signers.kms.auth.token-dir and
145-
// secret key name KMS_AUTH_TOKEN
146-
filePath := filepath.Join(dir, tokenEnv)
147-
fileData, err := os.ReadFile(filePath)
140+
func getKMSAuthToken(path string) (string, error) {
141+
fileData, err := os.ReadFile(path)
148142
if err != nil {
149-
return "", fmt.Errorf("reading file %q in directory %q: %w", tokenEnv, dir, err)
143+
return "", fmt.Errorf("reading file in %q: %w", path, err)
150144
}
151145

152146
// A trailing newline is fairly common in mounted files, so remove it.

pkg/chains/signing/kms/kms_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"net/http"
2222
"net/http/httptest"
2323
"os"
24-
"path/filepath"
2524
"testing"
2625

2726
"github.com/stretchr/testify/assert"
@@ -137,7 +136,7 @@ func TestGetKMSAuthToken_NotADirectory(t *testing.T) {
137136
defer os.Remove(tempFile.Name())
138137

139138
token, err := getKMSAuthToken(tempFile.Name())
140-
assert.Error(t, err)
139+
assert.Equal(t, err, nil)
141140
assert.Equal(t, "", token)
142141
}
143142

@@ -151,13 +150,14 @@ func TestGetKMSAuthToken_FileNotFound(t *testing.T) {
151150

152151
// Test for verifying return value of getKMSAuthToken
153152
func TestGetKMSAuthToken_ValidToken(t *testing.T) {
154-
tempDir := t.TempDir() // Creates a temporary directory
155-
tokenPath := filepath.Join(tempDir, "KMS_AUTH_TOKEN")
153+
tempFile, err := os.CreateTemp("", "vault-token")
154+
assert.NoError(t, err)
155+
defer os.Remove(tempFile.Name())
156156

157-
err := os.WriteFile(tokenPath, []byte("test-token"), 0644) // write a sample token "test-token"
157+
err = os.WriteFile(tempFile.Name(), []byte("test-token"), 0644) // write a sample token "test-token"
158158
assert.NoError(t, err)
159159

160-
token, err := getKMSAuthToken(tempDir)
160+
token, err := getKMSAuthToken(tempFile.Name())
161161
assert.NoError(t, err)
162162
assert.Equal(t, "test-token", token) // verify the value returned by getKMSAuthToken matches "test-token"
163163
}

pkg/config/config.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ type KMSSigner struct {
9191

9292
// KMSAuth configures authentication to the KMS server
9393
type KMSAuth struct {
94-
Address string
95-
Token string
96-
TokenDir string
97-
OIDC KMSAuthOIDC
98-
Spire KMSAuthSpire
94+
Address string
95+
Token string
96+
TokenPath string
97+
OIDC KMSAuthOIDC
98+
Spire KMSAuthSpire
9999
}
100100

101101
// KMSAuthOIDC configures settings to authenticate with OIDC
@@ -193,7 +193,7 @@ const (
193193
kmsAuthAddress = "signers.kms.auth.address"
194194
kmsAuthToken = "signers.kms.auth.token"
195195
kmsAuthOIDCPath = "signers.kms.auth.oidc.path"
196-
kmsAuthTokenDir = "signers.kms.auth.token-dir" // #nosec G101
196+
kmsAuthTokenPath = "signers.kms.auth.token-path" // #nosec G101
197197
kmsAuthOIDCRole = "signers.kms.auth.oidc.role"
198198
kmsAuthSpireSock = "signers.kms.auth.spire.sock"
199199
kmsAuthSpireAudience = "signers.kms.auth.spire.audience"
@@ -313,7 +313,7 @@ func NewConfigFromMap(data map[string]string) (*Config, error) {
313313
asString(kmsSignerKMSRef, &cfg.Signers.KMS.KMSRef),
314314
asString(kmsAuthAddress, &cfg.Signers.KMS.Auth.Address),
315315
asString(kmsAuthToken, &cfg.Signers.KMS.Auth.Token),
316-
asString(kmsAuthTokenDir, &cfg.Signers.KMS.Auth.TokenDir),
316+
asString(kmsAuthTokenPath, &cfg.Signers.KMS.Auth.TokenPath),
317317
asString(kmsAuthOIDCPath, &cfg.Signers.KMS.Auth.OIDC.Path),
318318
asString(kmsAuthOIDCRole, &cfg.Signers.KMS.Auth.OIDC.Role),
319319
asString(kmsAuthSpireSock, &cfg.Signers.KMS.Auth.Spire.Sock),

0 commit comments

Comments
 (0)