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

refactor: break --insecure into separate flags #2936

Merged
merged 2 commits into from
Sep 13, 2024

Conversation

joonas
Copy link
Contributor

@joonas joonas commented Aug 28, 2024

Description

Attempting to break up the --insecure global flag into four separate flags:

  • --plain-http
  • --insecure-skip-tls-verify
  • --skip-signature-validation

Related Issue

Fixes #2860

Relates to #

Checklist before merging

@joonas joonas requested review from a team as code owners August 28, 2024 03:14
Copy link

netlify bot commented Aug 28, 2024

Deploy Preview for zarf-docs canceled.

Name Link
🔨 Latest commit 868c7c0
🔍 Latest deploy log https://app.netlify.com/sites/zarf-docs/deploys/66e2fce0e2bc7d0008ec16d7

@AustinAbro321
Copy link
Contributor

Great question, unfortunately the insecure flag is pretty overloaded. I think it'll be better to just create two more flags to replace it's behavior

For this block, add a flag called --insecure-no-shasum to just the zarf package pull command zarf/src/pkg/packager/sources/url.go

For this block, add a flag called --insecure-no-signature-validation to the zarf package command zarf/src/pkg/packager/sources/validate.go

You can add these new fields to the types.ZarfPackageOptions struct

Copy link
Contributor

@AustinAbro321 AustinAbro321 left a comment

Choose a reason for hiding this comment

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

Great start, left some feedback. Could you also replace the uses of --insecure in the test suite. Leave one use of --insecure for each new flag so we can test that the flag still works though deprecated.

src/cmd/root.go Outdated Show resolved Hide resolved
src/cmd/root.go Outdated Show resolved Hide resolved
src/config/config.go Outdated Show resolved Hide resolved
src/cmd/root.go Outdated Show resolved Hide resolved
@joonas joonas force-pushed the refactor/break-apart-insecure-flag branch 6 times, most recently from 38a4cd8 to cac41bc Compare August 29, 2024 05:27
@joonas joonas changed the title refactor: break --insecure into --http-only and --tls-skip-verify refactor: break --insecure into separate flags Aug 29, 2024
@joonas joonas force-pushed the refactor/break-apart-insecure-flag branch 2 times, most recently from 6910fe6 to 613ae19 Compare August 29, 2024 05:35
@joonas
Copy link
Contributor Author

joonas commented Aug 29, 2024

@AustinAbro321 appreciate all the feedback, I tried to make sure I addressed it diligently, but please let me know if I missed the mark somewhere.

I haven't yet had a chance to revisit the use of --insecure in the test suite, but on a cursory look across the tests that contain the flag I noticed there's probably a combination of the above flag changes should be applied.

My plan for how I was going to address the tests is as follows:

  1. Where --insecure is being replaced with --insecure-skip-tls-verify and --plain-http, replace the --insecure flag with both of those in each case
  2. Where --insecure is being replaced with --insecure-no-signature-validation, apply that across the impacted examples
  3. Where --insecure is being replaced with --insecure-no-shasum, apply that across the impacted examples

Does that roughly line up with what you had in mind?

@phillebaba
Copy link
Member

phillebaba commented Aug 29, 2024

Some comments about this change. First of all we should stop adding things to the whole lang package as it is something that should be removed. Second of all I don't see the point of adding an "insecure" prefix to all of these flags. I am fine with --insecure-skip-tls-verify and --plain-http as they are common in other projects. The other two flags should be called something else or not exist at all. I suggest renaming --insecure-no-signature-validation to --skip-signature-validation.

I'm confused on the point of being able to disable digest verification while pulling? If the digests do not match something has gone very wrong. It also result in confusion for users in the future who assume that a package pulled has the expected digest.

@AustinAbro321
Copy link
Contributor

Yeah that looks like a solid strategy for changing the flag in tests @joonas

Good point @phillebaba, I doubt anyone is relying on the insecure feature for zarf package pull and if they are they shouldn't be. I also like --skip-signature-validation better

@joonas joonas force-pushed the refactor/break-apart-insecure-flag branch from b67d55e to 0896cb9 Compare September 1, 2024 22:54
@joonas
Copy link
Contributor Author

joonas commented Sep 1, 2024

I believe I've now addressed all of test cases and instances of where the flags were used 🙂

@joonas joonas force-pushed the refactor/break-apart-insecure-flag branch from 0896cb9 to 5352382 Compare September 1, 2024 23:02
Copy link
Member

@phillebaba phillebaba left a comment

Choose a reason for hiding this comment

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

Looks good I have a small thing that we need to verify if it is an issue or not before merging.

Copy link

codecov bot commented Sep 3, 2024

@phillebaba
Copy link
Member

@joonas I have verified that setting a pre run function in a sub command disables the root pre run. Which would explain why the tests are currently failing.

@joonas
Copy link
Contributor Author

joonas commented Sep 4, 2024

@joonas I have verified that setting a pre run function in a sub command disables the root pre run. Which would explain why the tests are currently failing.

Ah, it looks like to enable this behavior, the EnableTraverseRunHooks variable introduced in spf13/cobra#2044 needs to be set to true.

Does that seem like a reasonable change to make, or would you rather have the logic for setting pkgConfig.PkgOpts.SkipSignatureValidation to true if config.CommonOptions.Insecure is set to true copied to each sub command under the package command where it might be used?

I'm fine to go either way if changing the global flag in Cobra seems like too much of a behavior change to resolve this.

@phillebaba
Copy link
Member

Looks like my comments about the pre run functions did not make it with my review. Or I cant find it anymore.

In it I shared that I was unsure about enabling EnableTraverseRunHooks due to it being a global variable. My first thought when finding the same issue that you did a while back was to enable it. However because Zarf embeds other commands it makes me unsure if this would cause unexpected behavior in these tools.

In the end we probably want to get away from the shared package options struct which is currently in use. My other suggestion would be to put it in the root pre run function. Thinking about it now I would prefer the code duplication over that option.

@joonas joonas force-pushed the refactor/break-apart-insecure-flag branch 5 times, most recently from b00371e to d501d49 Compare September 7, 2024 03:33
@joonas
Copy link
Contributor Author

joonas commented Sep 7, 2024

@AustinAbro321 @phillebaba I finally had a chance to go back and fix the one e2e test that was failing due to the help text changes.

I've also re-generated the command docs pages to incorporate the flag changes and I went ahead and rebased on top of the latest changes (as of Friday evening)

This should hopefully be all that's needed to have the test suite now pass with flying colors 🙂

Copy link
Contributor

@AustinAbro321 AustinAbro321 left a comment

Choose a reason for hiding this comment

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

It's close, requested a few more changes. Thank you for taking this on.

src/test/e2e/11_oci_pull_inspect_test.go Outdated Show resolved Hide resolved
src/test/e2e/11_oci_pull_inspect_test.go Outdated Show resolved Hide resolved
src/cmd/package.go Outdated Show resolved Hide resolved
Fixes zarf-dev#2860

Signed-off-by: Joonas Bergius <joonas@bergi.us>
Copy link
Contributor

@AustinAbro321 AustinAbro321 left a comment

Choose a reason for hiding this comment

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

LGTM! Will need @phillebaba to approve as well

Copy link
Member

@phillebaba phillebaba left a comment

Choose a reason for hiding this comment

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

LGTM

@phillebaba phillebaba added this pull request to the merge queue Sep 13, 2024
Merged via the queue into zarf-dev:main with commit 90a4331 Sep 13, 2024
40 checks passed
@joonas joonas deleted the refactor/break-apart-insecure-flag branch September 13, 2024 21:39
mjnagel pushed a commit to defenseunicorns/uds-core that referenced this pull request Sep 20, 2024
This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| ghcr.io/zarf-dev/packages/init | minor | `v0.39.0` -> `v0.40.1` |
| [zarf-dev/zarf](https://redirect.github.com/zarf-dev/zarf) | minor |
`v0.39.0` -> `v0.40.1` |

---

> [!WARNING]
> Some dependencies could not be looked up. Check the Dependency
Dashboard for more information.

---

### Release Notes

<details>
<summary>zarf-dev/zarf (zarf-dev/zarf)</summary>

###
[`v0.40.1`](https://redirect.github.com/zarf-dev/zarf/releases/tag/v0.40.1)

[Compare
Source](https://redirect.github.com/zarf-dev/zarf/compare/v0.40.0...v0.40.1)

#### What's Changed

- chore(deps): bump actions/create-github-app-token from 1.10.3 to
1.10.4 by [@&#8203;dependabot](https://redirect.github.com/dependabot)
in
[zarf-dev/zarf#2968
- fix: imported helm overrides by
[@&#8203;rjferguson21](https://redirect.github.com/rjferguson21) in
[zarf-dev/zarf#2967
- chore: only show config file if there is one by
[@&#8203;catsby](https://redirect.github.com/catsby) in
[zarf-dev/zarf#2985
- refactor: trim named returns in pkg
[#&#8203;2950](https://redirect.github.com/zarf-dev/zarf/issues/2950) by
[@&#8203;mkcp](https://redirect.github.com/mkcp) in
[zarf-dev/zarf#2979
- chore: finish removing named returns outside of package and extensions
[#&#8203;2950](https://redirect.github.com/zarf-dev/zarf/issues/2950) by
[@&#8203;mkcp](https://redirect.github.com/mkcp) in
[zarf-dev/zarf#2987
- chore: ensure we return zeroed value when returning errors by
[@&#8203;mkcp](https://redirect.github.com/mkcp) in
[zarf-dev/zarf#2988
- chore(deps): bump actions/create-github-app-token from 1.10.4 to
1.11.0 by [@&#8203;dependabot](https://redirect.github.com/dependabot)
in
[zarf-dev/zarf#2991
- refactor: break --insecure into separate flags by
[@&#8203;joonas](https://redirect.github.com/joonas) in
[zarf-dev/zarf#2936
- ci: stop codeql on merge queue by
[@&#8203;AustinAbro321](https://redirect.github.com/AustinAbro321) in
[zarf-dev/zarf#2934
- fix: add shasum flag and test for https pull by
[@&#8203;AustinAbro321](https://redirect.github.com/AustinAbro321) in
[zarf-dev/zarf#2998
- chore(deps): bump github/codeql-action from 3.26.6 to 3.26.7 by
[@&#8203;dependabot](https://redirect.github.com/dependabot) in
[zarf-dev/zarf#2997
- refactor: pull command by
[@&#8203;phillebaba](https://redirect.github.com/phillebaba) in
[zarf-dev/zarf#2989
- docs: update dos-games refs by
[@&#8203;jasonwashburn](https://redirect.github.com/jasonwashburn) in
[zarf-dev/zarf#3004
- refactor: lint by
[@&#8203;phillebaba](https://redirect.github.com/phillebaba) in
[zarf-dev/zarf#3000
- refactor: mirror-resources by
[@&#8203;phillebaba](https://redirect.github.com/phillebaba) in
[zarf-dev/zarf#2975
- fix: gittributes to ignore image file endings by
[@&#8203;phillebaba](https://redirect.github.com/phillebaba) in
[zarf-dev/zarf#3012

#### New Contributors

- [@&#8203;rjferguson21](https://redirect.github.com/rjferguson21) made
their first contribution in
[zarf-dev/zarf#2967
- [@&#8203;catsby](https://redirect.github.com/catsby) made their first
contribution in
[zarf-dev/zarf#2985
- [@&#8203;mkcp](https://redirect.github.com/mkcp) made their first
contribution in
[zarf-dev/zarf#2979
- [@&#8203;joonas](https://redirect.github.com/joonas) made their first
contribution in
[zarf-dev/zarf#2936

**Full Changelog**:
zarf-dev/zarf@v0.39.0...v0.40.1

###
[`v0.40.0`](https://redirect.github.com/zarf-dev/zarf/compare/v0.39.0...v0.40.0)

[Compare
Source](https://redirect.github.com/zarf-dev/zarf/compare/v0.39.0...v0.40.0)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these
updates again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR was generated by [Mend Renovate](https://mend.io/renovate/).
View the [repository job
log](https://developer.mend.io/github/defenseunicorns/uds-core).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC44MC4wIiwidXBkYXRlZEluVmVyIjoiMzguODAuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
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.

Break apart --insecure
3 participants