-
Notifications
You must be signed in to change notification settings - Fork 157
Native SGC support for the operator #3231
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
s-alad
wants to merge
8
commits into
main
Choose a base branch
from
saad/sgc-binary-operator
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
8 commits
Select commit
Hold shift + click to select a range
c731965
native SGC usage in the operator
s-alad 5c75122
increase timeout
s-alad 0332b9c
Fix SGC backend precedence and packaging boundary
s-alad cfa1fb4
Cover SGC operator configuration
s-alad f50f10e
Bundle SGC in the public Operator image
s-alad 6e54f65
Select SGC release flavor in image builds
s-alad c8b384c
fix secret backend configuration parsing
s-alad 8daaa1c
Update Dockerfile
s-alad 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,14 +25,22 @@ import ( | |
| var ( | ||
| secretBackendCommand = "" | ||
| secretBackendArgs = []string{} | ||
| secretBackendType = "" | ||
| secretBackendConfig = map[string]any{} | ||
| ) | ||
|
|
||
| const ( | ||
| defaultCmdOutputMaxSize = 1024 * 1024 | ||
| defaultCmdTimeout = 5 * time.Second | ||
| defaultCmdTimeout = 30 * time.Second | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed to 30s since both the regular datadog-agent and sgc default to 30s |
||
|
|
||
| // PayloadVersion represents the version of the SB API | ||
| PayloadVersion = "1.0" | ||
| // sgcPayloadVersion is the API version sent when resolving via the embedded secret-generic-connector, | ||
| // whose payload additionally carries the backend "type" and "config". | ||
| sgcPayloadVersion = "1.1" | ||
|
|
||
| // defaultSGCBinaryPath is the embedded secret-generic-connector binary shipped in the operator image. | ||
| defaultSGCBinaryPath = "/usr/local/bin/secret-generic-connector" | ||
| ) | ||
|
|
||
| // SetSecretBackendCommand set the secretBackendCommand var | ||
|
|
@@ -45,11 +53,41 @@ func SetSecretBackendArgs(args []string) { | |
| secretBackendArgs = args | ||
| } | ||
|
|
||
| // SetSecretBackendType sets the secret backend type used by the embedded | ||
| // secret-generic-connector (e.g. "hashicorp.vault"). When set with an empty | ||
| // secret backend command, secrets are resolved via the embedded SGC binary. | ||
| func SetSecretBackendType(backendType string) { | ||
| secretBackendType = backendType | ||
| } | ||
|
|
||
| // SetSecretBackendConfig sets the secret backend config passed to the | ||
| // secret-generic-connector in the resolution payload. | ||
| func SetSecretBackendConfig(config map[string]any) { | ||
| secretBackendConfig = config | ||
| } | ||
|
|
||
| // NewSecretBackend returns a new SecretBackend instance | ||
| func NewSecretBackend() *SecretBackend { | ||
| cmd := secretBackendCommand | ||
| cmdArgs := secretBackendArgs | ||
| backendType := secretBackendType | ||
| backendConfig := secretBackendConfig | ||
|
|
||
| if cmd != "" { | ||
| // An explicit command uses the legacy secret-backend protocol. | ||
| backendType = "" | ||
| backendConfig = nil | ||
| } else if backendType != "" { | ||
| // A backend type without a command uses the embedded SGC binary. | ||
| cmd = defaultSGCBinaryPath | ||
| cmdArgs = nil | ||
| } | ||
|
|
||
| return &SecretBackend{ | ||
| cmd: secretBackendCommand, | ||
| cmdArgs: secretBackendArgs, | ||
| cmd: cmd, | ||
| cmdArgs: cmdArgs, | ||
| backendType: backendType, | ||
| backendConfig: backendConfig, | ||
| cmdOutputMaxSize: defaultCmdOutputMaxSize, | ||
| cmdTimeout: defaultCmdTimeout, | ||
| } | ||
|
|
@@ -64,19 +102,31 @@ func (sb *SecretBackend) Decrypt(encrypted []string) (map[string]string, error) | |
| return sb.fetchSecret(encrypted) | ||
| } | ||
|
|
||
| // buildPayload assembles the JSON payload sent to the secret backend binary. | ||
| func (sb *SecretBackend) buildPayload(handles []string) map[string]any { | ||
| if sb.backendType != "" { | ||
| return map[string]any{ | ||
| "version": sgcPayloadVersion, | ||
| "secrets": handles, | ||
| "type": sb.backendType, | ||
| "config": sb.backendConfig, | ||
| "secret_backend_timeout": sb.cmdTimeout.Seconds(), | ||
| } | ||
| } | ||
| return map[string]any{ | ||
| "version": PayloadVersion, | ||
| "secrets": handles, | ||
| } | ||
| } | ||
|
|
||
| // fetchSecret tries to get secrets by executing the secret backend command | ||
| func (sb *SecretBackend) fetchSecret(encrypted []string) (map[string]string, error) { | ||
| handles, err := extractHandles(encrypted) | ||
| if err != nil { | ||
| return nil, NewDecryptorError(err, false) | ||
| } | ||
|
|
||
| payload := map[string]any{ | ||
| "version": PayloadVersion, | ||
| "secrets": handles, | ||
| } | ||
|
|
||
| jsonPayload, err := json.Marshal(payload) | ||
| jsonPayload, err := json.Marshal(sb.buildPayload(handles)) | ||
| if err != nil { | ||
| return nil, NewDecryptorError(err, false) | ||
| } | ||
|
|
||
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
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.