-
Notifications
You must be signed in to change notification settings - Fork 2k
EnsureRightLabelOnSecret: dual label support for workflow_owner and org_id #21680
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ebf9abc
EnsureRightLabelOnSecret: dual label support for workflow_owner and o…
prashantkumar1982 42bfb93
fix testifylint: use require.Error for error assertions
prashantkumar1982 43b6660
fix: use dedicated label functions for workflowOwner and orgID
prashantkumar1982 92144c1
merge develop into pyadav/vault-dual-label-support
prashantkumar1982 6cd4f83
gate orgID label check behind VaultOrgIdAsSecretOwnerEnabled limiter
prashantkumar1982 5542f66
fix goimports ordering in system-tests vault.go
prashantkumar1982 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package vaultutils | ||
|
|
||
| import ( | ||
| "crypto/sha256" | ||
| "encoding/hex" | ||
| "fmt" | ||
|
|
||
| "github.com/ethereum/go-ethereum/common" | ||
| "github.com/smartcontractkit/tdh2/go/tdh2/tdh2easy" | ||
| ) | ||
|
|
||
| // WorkflowOwnerToLabel converts a workflow owner string to a 32-byte TDH2 ciphertext | ||
| // label using the Ethereum address encoding: 12 zero bytes followed by the 20-byte address. | ||
| // This matches the legacy label format used when secrets are encrypted with a workflow owner. | ||
| func WorkflowOwnerToLabel(owner string) [32]byte { | ||
| var label [32]byte | ||
| addr := common.HexToAddress(owner) | ||
| copy(label[12:], addr.Bytes()) | ||
| return label | ||
| } | ||
|
|
||
| // OrgIDToLabel converts an org_id string to a 32-byte TDH2 ciphertext label | ||
| // using SHA256 hashing. | ||
| func OrgIDToLabel(orgID string) [32]byte { | ||
| return sha256.Sum256([]byte(orgID)) | ||
| } | ||
|
|
||
| // EncryptSecretWithWorkflowOwner encrypts a secret using a TDH2 public key with a label | ||
| // derived from a workflow owner's Ethereum address (left-padded to 32 bytes). | ||
| func EncryptSecretWithWorkflowOwner(secret string, masterPublicKey *tdh2easy.PublicKey, owner common.Address) (string, error) { | ||
| var label [32]byte | ||
| copy(label[12:], owner.Bytes()) | ||
| return encryptWithLabel(secret, masterPublicKey, label) | ||
| } | ||
|
|
||
| // EncryptSecretWithOrgID encrypts a secret using a TDH2 public key with a label | ||
| // derived from an org_id (SHA256 hash of the org_id string). | ||
| func EncryptSecretWithOrgID(secret string, masterPublicKey *tdh2easy.PublicKey, orgID string) (string, error) { | ||
| label := sha256.Sum256([]byte(orgID)) | ||
| return encryptWithLabel(secret, masterPublicKey, label) | ||
| } | ||
|
|
||
| func encryptWithLabel(secret string, masterPublicKey *tdh2easy.PublicKey, label [32]byte) (string, error) { | ||
| cipher, err := tdh2easy.EncryptWithLabel(masterPublicKey, []byte(secret), label) | ||
| if err != nil { | ||
| return "", fmt.Errorf("failed to encrypt secret: %w", err) | ||
| } | ||
| cipherBytes, err := cipher.Marshal() | ||
| if err != nil { | ||
| return "", fmt.Errorf("failed to marshal encrypted secret: %w", err) | ||
| } | ||
| return hex.EncodeToString(cipherBytes), 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@prashantkumar1982 Is it worth accepting a common.Address here? Atm HexToAddress will truncate to the right length; I also wonder what it will do if the input isn't hex 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Feel free to follow up if this is urgent btw)