-
Notifications
You must be signed in to change notification settings - Fork 0
feat(buildsecrets): sync tenant build-secrets from AWS Secrets Manager (no ESO) #10
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
Open
nicacioliveira
wants to merge
5
commits into
main
Choose a base branch
from
feat/tenant-build-secrets-sync
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ebbe383
feat(buildsecrets): sync tenant build-secrets via ExternalSecret
nicacioliveira 9ff4a14
fix(buildsecrets): decouple site-name derivation from Valkey reserved…
nicacioliveira 6f7c57a
refactor(buildsecrets): operator manages K8s Secret directly, no ESO
nicacioliveira 82347d3
fix(buildsecrets): silence unparam lint on getSecret helper
nicacioliveira 152a4b6
fix(buildsecrets): reject JSON null payload from AWS Secrets Manager
nicacioliveira File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| /* | ||
| Copyright 2025. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
| */ | ||
|
|
||
| package buildsecrets | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
|
|
||
| "github.com/aws/aws-sdk-go-v2/aws" | ||
| "github.com/aws/aws-sdk-go-v2/config" | ||
| "github.com/aws/aws-sdk-go-v2/service/secretsmanager" | ||
| smtypes "github.com/aws/aws-sdk-go-v2/service/secretsmanager/types" | ||
| ) | ||
|
|
||
| // awsSecretsManagerAPI captures the AWS Secrets Manager surface this | ||
| // package uses. Defined so tests can swap a mock without depending on | ||
| // the real SDK client. | ||
| type awsSecretsManagerAPI interface { | ||
| GetSecretValue(ctx context.Context, params *secretsmanager.GetSecretValueInput, optFns ...func(*secretsmanager.Options)) (*secretsmanager.GetSecretValueOutput, error) | ||
| } | ||
|
|
||
| // AWSSource resolves keys against AWS Secrets Manager. Credentials come | ||
| // from the ambient environment (Pod Identity / IRSA in-cluster; default | ||
| // chain locally). Region is taken from the AWS_REGION env var or the | ||
| // default chain — usually set by the EKS Pod Identity webhook. | ||
| type AWSSource struct { | ||
| api awsSecretsManagerAPI | ||
| } | ||
|
|
||
| // NewAWSSource builds a Source backed by the live Secrets Manager | ||
| // client. The reconciler keeps the same instance for its lifetime. | ||
| func NewAWSSource(ctx context.Context) (*AWSSource, error) { | ||
| cfg, err := config.LoadDefaultConfig(ctx) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("load AWS config: %w", err) | ||
| } | ||
| return &AWSSource{api: secretsmanager.NewFromConfig(cfg)}, nil | ||
| } | ||
|
|
||
| // Get fetches the JSON-encoded secret at `key` and decodes it into a | ||
| // flat map. A missing key returns (nil, false, nil) — the natural | ||
| // "not provisioned yet" state for tenants that have opted in but not | ||
| // supplied data. | ||
| func (s *AWSSource) Get(ctx context.Context, key string) (map[string]string, bool, error) { | ||
| out, err := s.api.GetSecretValue(ctx, &secretsmanager.GetSecretValueInput{ | ||
| SecretId: aws.String(key), | ||
| }) | ||
| if err != nil { | ||
| var nfe *smtypes.ResourceNotFoundException | ||
| if errors.As(err, &nfe) { | ||
| return nil, false, nil | ||
| } | ||
| return nil, false, fmt.Errorf("get secret %q: %w", key, err) | ||
| } | ||
|
|
||
| if out.SecretString == nil { | ||
| // Binary secrets are not supported — builds inject env vars, | ||
| // not files, so a JSON object of strings is the only shape. | ||
| return nil, false, fmt.Errorf("secret %q has no SecretString (binary secret?)", key) | ||
| } | ||
|
|
||
| var data map[string]string | ||
| if err := json.Unmarshal([]byte(*out.SecretString), &data); err != nil { | ||
| return nil, false, fmt.Errorf("parse %q as JSON object of strings: %w", key, err) | ||
| } | ||
| // Reject JSON `null` (Unmarshal leaves the map nil without erroring). | ||
| // An empty object {} is fine and yields a non-nil empty map. | ||
| if data == nil { | ||
| return nil, false, fmt.Errorf("secret %q payload is JSON null; expected an object of strings", key) | ||
| } | ||
| return data, true, nil | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.