Skip to content
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

Ability to Use Regex-Based Validation for Sentinel, Safe, and Workload SPIFFE IDs #974

Merged
merged 2 commits into from
Jun 3, 2024

Conversation

v0lkan
Copy link
Contributor

@v0lkan v0lkan commented Jun 2, 2024

Regex-Based SPIFFE ID Validation

Description

This PR introduces regular-expression-based spiffe id validation.

In addition, we do additional sanitization checks on SPIFFE IDs (such as checking whether a SPIFFE ID starts with 'spiffe://' before accepting it.

Note that we will need a separate integration test, and also documentation updates, which are not a part of this PR and will be addressed by follow-up PRs.

Changes

  • SPIFFE ID validation parses the SPIFFE ID as a regex if it starts with a '^' character.
  • Additional sanitizations for SPIFFE ID validations.

Test Policy Compliance

Not created tests; I will amend tests as a follow-up PR.

I will also ensure that this branch passes the current tests before merging.

Documentation needs updating too; which, again will be done in a follow-up PR.

Code Quality

  • I have followed the coding standards for this project.
  • I have performed a self-review of my code.
  • My code is well-commented, particularly in areas that may be difficult
    to understand.

Documentation

Documentation will be udpated as a follow-up PR.

Checklist

Before you submit this PR, please make sure:

  • You have read the contributing guidelines and
    especially the test policy.
  • You have thoroughly tested your changes.
  • You have followed all the contributing guidelines for this project.
  • You understand and agree that your contributions will be publicly available
    under the project's license.

By submitting this pull request, you confirm that my contribution is made under
the terms of the project's license and that you have the authority to grant
these rights.


Thank you for your contribution to VMware Secrets Manager
🐢⚡️!

@v0lkan v0lkan self-assigned this Jun 2, 2024
@v0lkan v0lkan requested a review from BulldromeQ as a code owner June 2, 2024 21:40
@vmwclabot
Copy link

@v0lkan, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding Signed-off-by: John Doe <[email protected]> to the last line of each Git commit message. The e-mail address used to sign must match the e-mail address of the Git author. Click here to view the Developer Certificate of Origin agreement.

@@ -22,3 +22,11 @@ func SpiffeSocketUrl() string {
}
return p
}

func SpiffeTrustDomain() string {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If defined, the system will assume this one.

Of course, SPIRE should be configured accordingly for the new trust domain to work without issues.

trustDomain := SpiffeTrustDomain()
ns := NamespaceForVSecMSystem()

p = "spiffe://" + trustDomain + "/workload/" +
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense to have trust domain and namespace configurable.

There is not much of a use case that necessitates configuring the service account too; so it has been left hard-coded.

}

// IsWorkload returns true if the given SPIFFEID is a WorkloadIds ID.
// It does this by checking if the SPIFFEID has the SpiffeIdPrefixForWorkload
// as its prefix.
func IsWorkload(spiffeid string) bool {
return strings.HasPrefix(spiffeid, env.SpiffeIdPrefixForWorkload())
prefix := env.SpiffeIdPrefixForWorkload()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be validated both at the workload, and also at VSecM safe.

A malicious workload can easily fake or bypass configuration-based validations that depend on an environment variable or a mounted config file.

The authentication/validation should be mutual, and we should guard the security of core VSecM components with tight RBAC.

Or an alternative is to use a configuration file that can be accessed through a read-only API. But if the workload is a third-party workload that can opt-out from such validation, it is of little use. -- and the env vars that vsecm components use (such as safe and sentinel, etc) cannot be tampered with unless changing the source code of those components and recompiling them (or having a malicious cluster admin misconfiguring them, which then all bets will be off anyway.)

@vmwclabot
Copy link

@v0lkan, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding Signed-off-by: John Doe <[email protected]> to the last line of each Git commit message. The e-mail address used to sign must match the e-mail address of the Git author. Click here to view the Developer Certificate of Origin agreement.

v0lkan added 2 commits June 3, 2024 08:58
Signed-off-by: Volkan Ozcelik <[email protected]>
Signed-off-by: Volkan Ozcelik <[email protected]>
@v0lkan
Copy link
Contributor Author

v0lkan commented Jun 3, 2024

Tests are passing… merging this one.

@v0lkan v0lkan merged commit ccf7b00 into main Jun 3, 2024
@v0lkan v0lkan deleted the ovolkan/changes branch June 3, 2024 06:23
@v0lkan v0lkan restored the ovolkan/changes branch June 3, 2024 06:45
@v0lkan
Copy link
Contributor Author

v0lkan commented Jun 3, 2024

I don’t see some of my changes here.

Will create another PR.

@v0lkan v0lkan deleted the ovolkan/changes branch June 17, 2024 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants