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

Best-effort detection of potentially secret variables #665

Merged
merged 4 commits into from
Nov 14, 2023

Conversation

jsoriano
Copy link
Member

@jsoriano jsoriano commented Nov 14, 2023

What does this PR do?

Fails validation on variables that look like secrets and don't declare if they are secrets or not with the secret property.

This detection is based on two things:

  • The name of the variable contains strings like password, api_key or token.
  • The type of the variable is password.

Why is it important?

To encourage adoption of this feature to secure secrets in package policies.

Checklist

Related issues

@jsoriano jsoriano self-assigned this Nov 14, 2023
@jsoriano jsoriano requested a review from a team as a code owner November 14, 2023 12:43
if substringInSlice(e.Error(), redundant) {
continue
}
processedErrs = append(processedErrs, e)
Copy link
Member Author

Choose a reason for hiding this comment

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

Unrelated fix required for this change, but that I could move to a different PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Created also separate PR so we merge this fix in any case #666

anyOf:
- properties:
name:
pattern: "(password|api_key|access_key|token)"
Copy link
Member Author

Choose a reason for hiding this comment

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

@kpollich @nimarezainia this is the regexp pattern for variable names that we would detect as candidates to be secrets, is there any other string do you think we should add here?
Should we match with exact values instead of with substrings?

Copy link
Member

Choose a reason for hiding this comment

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

We could add the substring secret here as it will catch things like an AWS secret_access_key value. I think using substring matching is good to keep this generic.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added secret and passphrase, the latter is sometimes used for encrypted TLS keys.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We should juste be cautious with values like "secret_path" which might be caught by this check though.

Copy link
Member Author

Choose a reason for hiding this comment

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

We should juste be cautious with values like "secret_path" which might be caught by this check though.

Yep, in these cases they will need to set secret: false.

"manifest.yml",
[]string{
"field vars.0: variable identified as possible secret, secret parameter required to be set to true or false",
"field vars.1: variable identified as possible secret, secret parameter required to be set to true or false",
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the kind of errors package developers will see when upgrading to Package Spec 3.0.2.

Copy link
Member

Choose a reason for hiding this comment

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

This is the kind of errors package developers will see when upgrading to Package Spec 3.0.2.

Isn't this an enhancement? I'm surprised a new feature would fall into a patch version.

I'm also hesitant to jump right into requiring secret when it's still new functionality (sure, a dev can set secret: false but the way the error's presented, we're encouraging to set secret: true). Based on a recent issue I ran into trying to set secret: true (see elastic/kibana#154715 (comment)), I think it's worth adopting on a smaller set of integrations first.

Should using secret be encouraged, especially with new integrations? Definitely! But required? I'm not so sure.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hey @ebeahan,

I'm surprised a new feature would fall into a patch version.

Starting on Package Spec 3 we are not fully following semver. I understand this can be surprising. We use minors now for compatibility with the stack, and this change doesn't affect the compatibility with the stack, it only enhances validations. Secrets were already supported in the spec since 2.9.0.

It is an enhancement in the sense that it can prevent security risks. We have also considered as enhancements other "breaking" validations that we have introduced in the past to avoid problematic situations. We can reconsider this in any case if needed.

a dev can set secret: false but the way the error's presented, we're encouraging to set secret: true

I am open to suggestions regarding the error message.

Based on a recent issue I ran into trying to set secret: true (see elastic/kibana#154715 (comment))

This is an issue found in an snapshot build, that was fixed. We can still delay the introduction of this change though, 3.0.2 hasn't been released yet.

Copy link
Member Author

Choose a reason for hiding this comment

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

Starting on Package Spec 3 we are not fully following semver. I understand this can be surprising. We use minors now for compatibility with the stack, and this change doesn't affect the compatibility with the stack, it only enhances validations. Secrets were already supported in the spec since 2.9.0.

Updating versioning guidelines in the README taking recent changes into account #667

kpollich
kpollich previously approved these changes Nov 14, 2023
Copy link
Member

@kpollich kpollich left a comment

Choose a reason for hiding this comment

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

LGTM - thanks for getting this done quickly 🚀

jlind23
jlind23 previously approved these changes Nov 14, 2023
@elasticmachine
Copy link

💚 Build Succeeded

History

cc @jsoriano

ExcludeChecks: []string{"SVR00004"},
ExcludeChecks: []string{
// Allow to test unreleased features in "good" packages.
"PSR00001",
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@mrodm mrodm left a comment

Choose a reason for hiding this comment

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

👍

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.

6 participants