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

[3006.x] Fix x509_v2 state without changes can trigger file module to run in test mode #64269

Closed
wants to merge 5 commits into from

Conversation

lkubb
Copy link
Contributor

@lkubb lkubb commented May 10, 2023

What does this PR do?

In some cases, the x509_v2 state module can cause subsequent calls to the file modules to erroneously run in test mode.

What issues does this PR fix or reference?

Fixes: #64195

Previous Behavior

The file module sometimes runs in test mode.

New Behavior

The file module always runs in the expected mode.

Merge requirements satisfied?

Commits signed with GPG?

Yes

@salt-project-bot-prod-environment salt-project-bot-prod-environment bot changed the title Fix x509_v2 state without changes can trigger file module to run in test mode [master] Fix x509_v2 state without changes can trigger file module to run in test mode May 10, 2023
@lkubb lkubb force-pushed the x509v2-test-mode-interaction branch from ba63d03 to d87eb20 Compare May 10, 2023 15:27
@lkubb lkubb changed the base branch from master to 3006.x May 10, 2023 15:27
@salt-project-bot-prod-environment salt-project-bot-prod-environment bot changed the title [master] Fix x509_v2 state without changes can trigger file module to run in test mode [3006.x] Fix x509_v2 state without changes can trigger file module to run in test mode May 10, 2023
@lkubb lkubb changed the title [3006.x] Fix x509_v2 state without changes can trigger file module to run in test mode [3006.x] Fix x509_v2 state without changes can trigger file module to run in test mode [DO NOT MERGE] May 10, 2023
@lkubb lkubb marked this pull request as ready for review May 10, 2023 15:32
@lkubb lkubb requested a review from a team as a code owner May 10, 2023 15:32
@lkubb lkubb requested review from garethgreenaway and removed request for a team May 10, 2023 15:32
@lkubb lkubb force-pushed the x509v2-test-mode-interaction branch from d87eb20 to 417f9d8 Compare May 10, 2023 15:34
@lkubb lkubb temporarily deployed to ci May 11, 2023 06:39 — with GitHub Actions Inactive
@lkubb lkubb temporarily deployed to ci May 11, 2023 06:39 — with GitHub Actions Inactive
@lkubb lkubb changed the title [3006.x] Fix x509_v2 state without changes can trigger file module to run in test mode [DO NOT MERGE] [3006.x] Fix x509_v2 state without changes can trigger file module to run in test mode May 11, 2023
@lkubb lkubb temporarily deployed to ci May 11, 2023 06:43 — with GitHub Actions Inactive
@lkubb lkubb temporarily deployed to ci May 11, 2023 07:54 — with GitHub Actions Inactive
@lkubb lkubb temporarily deployed to ci May 11, 2023 07:54 — with GitHub Actions Inactive
@lkubb lkubb temporarily deployed to ci May 11, 2023 07:54 — with GitHub Actions Inactive
@lkubb lkubb temporarily deployed to ci May 11, 2023 08:36 — with GitHub Actions Inactive
@lkubb lkubb temporarily deployed to ci May 11, 2023 08:36 — with GitHub Actions Inactive
@lkubb lkubb temporarily deployed to ci May 11, 2023 08:36 — with GitHub Actions Inactive
lkubb added 2 commits May 11, 2023 10:56
This is cosmetic in the current state since only in non-test mode
is file.managed actually called without the workaround.
@lkubb lkubb temporarily deployed to ci May 11, 2023 09:16 — with GitHub Actions Inactive
@lkubb lkubb temporarily deployed to ci May 11, 2023 09:16 — with GitHub Actions Inactive
@lkubb lkubb temporarily deployed to ci May 11, 2023 09:16 — with GitHub Actions Inactive
@lkubb lkubb temporarily deployed to ci May 11, 2023 10:31 — with GitHub Actions Inactive
@lkubb lkubb temporarily deployed to ci May 11, 2023 10:31 — with GitHub Actions Inactive
@lkubb lkubb temporarily deployed to ci May 11, 2023 10:31 — with GitHub Actions Inactive
@lkubb lkubb temporarily deployed to ci May 23, 2023 22:50 — with GitHub Actions Inactive
@lkubb lkubb temporarily deployed to ci May 23, 2023 23:04 — with GitHub Actions Inactive
@lkubb lkubb temporarily deployed to ci May 23, 2023 23:08 — with GitHub Actions Inactive
return res[next(iter(res))]
file_managed = __states__["file.managed"]
if test:
# calls via __salt__["state.single"](..., test=test)
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't the fix be in state.single if that call is what is causing the overwrite in __opts__?

Copy link
Contributor Author

@lkubb lkubb Jun 22, 2023

Choose a reason for hiding this comment

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

I suspect the problem is somewhere in the loader, though I'm neither qualified nor motivated to find out tbh. I have tried to debug a very similar problem with overriding __opts__ not being reversed in the Vault runner before. Also not sure if this workaround can be applied to state.single easily.

This specific bug breaks the x509_v2 state module pretty hard though and I suspect it will take a bit of time until someone figures out the root cause, if at all (since it's not a huge deal for most of Salt).

Edit: Note that in addition, by avoiding state.single this should run quite a bit more performant.

Copy link
Contributor

Choose a reason for hiding this comment

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

@Ch3LL can we merge it as is? It's a huge issue in 3006.x since there is a problem installing mcrypto to onedir and the only other way to use x509 state is to use x509_v2 which has that issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

@lkubb Mind checking the file.directory issue reported here #64195 (comment) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Oloremo Without having much to go on regarding the report, I fail to see how file.directory would behave differently with this patch atm. If anything, I would expect it the other way around (test to not be respected). Using file.directory instead of file.managed for the reproduction test in this PR succeeds as well. So my current assumption is that it's an unrelated issue or the patch was not applied correctly, barring any future (and more detailed) reports.

Copy link
Contributor

Choose a reason for hiding this comment

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

This bug is nicely distilled in this issue #62590. I think this should be addressed between salt/state.py and salt/loader/lazy.py which would fix it for all cases where we could run into this, not just x509_v2.

  • I've done some preliminary investigation and think this is something we can address in a 3006.x maintenance release.

  • We want all of Salt's dunders to be managed by the loader. Using func_globals_inject should be considered an anti-pattern.

  • We'd like to get to a place where opts is no longer mutable. This means in the long run we'll have to figure how a better way to handle __opts__["test"]. Currently the loader adds __opts__ to the modules it imports (at import time). The loader adds a copy of opts, not opts itself. This means updating __opts__["test"] or loader.opts after a loader has imported a module won't have any affect.

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 bug is nicely distilled in this issue #62590.

Do you mean that bug has the same source as the sticky __opts__ causing this issue with state.single or fixing that bug will remove the necessity for using state.single instead of __states__ here in the first place?

The problem is that the x509_v2 state module also overrides test for early checks to avoid signing certificates that are discarded directly after, e.g. by a missing parent dir without makedirs. So if it does not have the same cause, a restructuring of the x509_v2 state module would still be necessary (not the end of the world though).

Copy link
Contributor

@dwoz dwoz Jul 7, 2023

Choose a reason for hiding this comment

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

This bug is nicely distilled in this issue #62590.

fixing that bug will remove the necessity for using state.single instead of __states__ here in the first place?

I don't think we should need to refactor x509_v2 after fixing the bug. I will pull in your tests to the PR where this gets fixed so we can validate the issue is resolved.

Copy link
Contributor

Choose a reason for hiding this comment

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

@dwoz
It's been a month, any updates on this issue? I believe it block literally everyone who wants to use 3006.x and x509

Copy link
Contributor

@dwoz dwoz Aug 11, 2023

Choose a reason for hiding this comment

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

#64960 addresses this issue. I think this PR can be closed.

@Ch3LL Ch3LL requested a review from dwoz July 6, 2023 13:34
@Ch3LL Ch3LL temporarily deployed to ci July 6, 2023 13:52 — with GitHub Actions Inactive
@Ch3LL Ch3LL temporarily deployed to ci July 6, 2023 13:52 — with GitHub Actions Inactive
@Ch3LL Ch3LL temporarily deployed to ci July 6, 2023 13:54 — with GitHub Actions Inactive
@Ch3LL Ch3LL temporarily deployed to ci July 6, 2023 14:01 — with GitHub Actions Inactive
@Ch3LL Ch3LL temporarily deployed to ci July 6, 2023 14:11 — with GitHub Actions Inactive
@Ch3LL Ch3LL temporarily deployed to ci July 6, 2023 14:13 — with GitHub Actions Inactive
@saltstack saltstack deleted a comment from johnyang Jul 17, 2023
@Ch3LL Ch3LL temporarily deployed to ci August 7, 2023 20:30 — with GitHub Actions Inactive
@Ch3LL Ch3LL temporarily deployed to ci August 7, 2023 20:30 — with GitHub Actions Inactive
@Ch3LL Ch3LL temporarily deployed to ci August 7, 2023 20:31 — with GitHub Actions Inactive
@Ch3LL Ch3LL temporarily deployed to ci August 7, 2023 20:46 — with GitHub Actions Inactive
@Ch3LL Ch3LL temporarily deployed to ci August 7, 2023 20:47 — with GitHub Actions Inactive
@Ch3LL Ch3LL temporarily deployed to ci August 7, 2023 21:20 — with GitHub Actions Inactive
@lkubb
Copy link
Contributor Author

lkubb commented Aug 11, 2023

Superseded by #64960.

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.

[BUG] file.managed and file.symlink both run in test mode by default
7 participants