8000 VAULT-32657 deprecate duplicate attributes in HCL configs and policies by bosouza · Pull Request #30386 · hashicorp/vault · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

VAULT-32657 deprecate duplicate attributes in HCL configs and policies #30386

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 34 commits into from
May 23, 2025

Conversation

bosouza
Copy link
Contributor
@bosouza bosouza commented Apr 25, 2025

Description

This PR deprecates the usage of duplicate attributes in HCL configuration files and policy definitions. An example of a duplicate attribute is the following, which until support is fully removed will continue parsing to the last occurence of the attribute:

path "secret" {
  capabilities = ["read"]
  capabilities = ["read", "create", "update", "delete"]
}

Following our deprecation process, these changes correspond to the deprecation phase to be announced in v1.20 (and cherry picked to v1.19, likely out in v1.19.4), implementing the following:

  • CLI commands that take a configuration file will print WARNING: Duplicate keys found. A comprehensive list of those commands is: vault server, vault operator migrate, vault agent, vault proxy and vault operator diagnose;
  • CLI commands using a token helper file (under $HOME/.vault) with duplicate attributes will print a similar WARNING: Duplicate keys found message;
  • Any usages of a policy already stored in the system that contains duplicate attributes will print a warning on the server logs containing at least policy contains duplicate attributes. These include initial caching of policies after unseal, reading policies via the API, using a token that references such a policy among others;
  • Creating or updating a policy to have duplicate attributes will cause a message to be added to the Warnings field in the server response.

This was accomplished by upgrading the hcl dependency to reject duplicate attributes, and using the new functions exposed in hashicorp/hcl#707 to create a helper function ParseAndCheckForDuplicateHclAttributes that parses the hcl and reports if there are duplicates.

Unfortunately, the library also had a behavior change that I traced back to hashicorp/hcl@e80118a not being included in the v1.0.1-vault-5 of the library we're using (as it was already included in v1.0.1-vault-4). This means that an approach we've been using of double-parsing some config fields now doesn't work the same anymore, which I'm trying to fix by removing the automatic parsing from the fields that are manually parsed. More details on the specific commit message.

Throughout the code I've left these TODO (HCL_DUP_KEYS_DEPRECATION) comments to more easily find all the places that will need to be changed/deleted after each of the following steps on the deprecation process.

For 1.20 we will only have these warnings, but on v1.21 all the operations described above involving HCL definitions with duplicate attributes will simply fail. We will add an environment variable though to allow the behavior to be rolled back to a log-only mode, at least until the final removal is completed on a future version.

Jira: VAULT-32657
ADR: VLT-006: Deprecate and remove duplicate attributes in HCL files in Vault

TODO only if you're a HashiCorp employee

  • Backport Labels: If this fix needs to be backported, use the appropriate backport/ label that matches the desired release branch. Note that in the CE repo, the latest release branch will look like backport/x.x.x, but older release branches will be backport/ent/x.x.x+ent.
    • LTS: If this fixes a critical security vulnerability or severity 1 bug, it will also need to be backported to the current LTS versions of Vault. To ensure this, use all available enterprise labels.
  • ENT Breakage: If this PR either 1) removes a public function OR 2) changes the signature
    of a public function, even if that change is in a CE file, double check that
    applying the patch for this PR to the ENT repo and running tests doesn't
    break any tests. Sometimes ENT only tests rely on public functions in CE
    files.
  • Jira: If this change has an associated Jira, it's referenced either
    in the PR description, commit message, or branch name.
  • RFC: If this change has an associated RFC, please link it in the description.
  • ENT PR: If this change has an associated ENT PR, please link it in the
    description. Also, make sure the changelog is in this PR, not in your ENT PR.

bosouza added 10 commits April 25, 2025 12:21
This upgrades the hcl dependency for the API pkg,
and adapts its usage so users of our API pkg are
not affected. There's no good way of communicating
a warning via a library call so we don't.

The tokenHelper which is used by all Vault CLI
commands in order to create the Vault client, as
well as directly used by the login and server
commands, is implemented on the api pkg, so this
upgrade also affects all of those commands. Seems
like this was only moved to the api pkg because
the Terraform provider uses it, and I thought
creating a full copy of all those files back under
command would be too much spaghetti.

Also leaving some TODOs to make next deprecation
steps easier.
- vault agent (unit test on CMD warning)
- vault proxy (unit test on CMD warning)
- vault server (no test for the warning)
- vault operator diagnose (no tests at all, uses the
same function as vault server
Following operations can trigger this warning when they run into a policy
with duplicate attributes:
* replication filtered path namespaces invalidation
* policy read API
* building an ACL (for many different purposes like most authZ operations)
* looking up DR token policies
* creating a token with named policies
* when caching the policies for all namespaces during unseal
No unit tests on these as new test infra would have to be built on all.
Operations affected, which will now print a log warning when the retrieved
token has an inline policy with duplicate attributes:
* capabilities endpoints in sys mount
* handing events under a subscription with a token with duplicate
attrs in inline policies
* token used to create another token has duplicate attrs in inline
policies (sudo check)
* all uses of fetchACLTokenEntryAndEntity when the request uses a
token with inline policies with duplicate attrs. Almost all reqs
are subject to this
* when tokens are created with inline policies (unclear exactly how that
can happen)
@github-actions github-actions bot added the hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed label Apr 25, 2025
@bosouza bosouza changed the title VAULT-32657 deprecate duplicate attributes in HCL files VAULT-32657 deprecate duplicate attributes in HCL configs and policies Apr 25, 2025
Copy link
github-actions bot commented Apr 25, 2025

CI Results:
All Go tests succeeded! ✅

@bosouza bosouza added this to the 1.20.0-rc milestone Apr 25, 2025
@bosouza bosouza marked this pull request as ready for review April 25, 2025 17:21
@bosouza bosouza requested review from a team as code owners April 25, 2025 17:21
Copy link
github-actions bot commented Apr 25, 2025

Build Results:
All builds succeeded! ✅

bosouza added 3 commits April 25, 2025 18:45
good thing it was covered by unit tests
This commit in the hcl library was not in the
v1.0.1-vault-5 version we're using but is
included in v1.0.1-vault-7:
hashicorp/hcl@e80118a

This thing of reusing when parsing means that
our approach of manually re-parsing fields
on top of fields that have already been parsed
by the hcl annotation causes strings (maybe
more?) to concatenate.

Fix that by removing annotation. There's
actually more occurrences of this thing of
automatically parsing something that is also
manually parsing. In some places we could
just remove the boilerplate manual parsing, in
others we better remove the auto parsing, but
I don't wanna pull at that thread right now. I
just checked that all places at least fully
overwrite the automatically parsed field
instead of reusing it as the target of the
decode call. The only exception is the AOP
field on ent but that doesn't have maps or
slices, so I think it's fine.

An alternative approach would be to ensure
that the auto-parsed value is discarded,
like the current parseCache function does

note how it's template not templates
mpalmi
mpalmi previously approved these changes May 2, 2025
bosouza and others added 4 commits May 2, 2025 20:07
Co-authored-by: Sarah Chavis <62406755+schavis@users.noreply.github.com>
Co-authored-by: Sarah Chavis <62406755+schavis@users.noreply.github.com>
@bosouza
Copy link
Contributor Author
bosouza commented May 5, 2025

I removed all doc changes from this PR and created a separate one to be merged and backported after the 1.20 release branch has been cut #30512.

For future reference, we discussed a bit this process in slack

@bosouza bosouza requested review from mpalmi and schavis May 5, 2025 14:39
@bosouza bosouza enabled auto-merge (squash) May 5, 2025 14:51
mpalmi
mpalmi previously approved these changes May 22, 2025
schavis
schavis previously approved these changes May 23, 2025
@bosouza bosouza dismissed stale reviews from mpalmi and schavis via 7a503c1 May 23, 2025 13:38
@bosouza bosouza disabled auto-merge May 23, 2025 18:12
@bosouza bosouza merged commit 0b91571 into main May 23, 2025
106 of 107 checks passed
@bosouza bosouza deleted the bosouza-deprecate-dup-attr branch May 23, 2025 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/1.19.x hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0