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

CHAOSPLT-68: Replace ddmark with go-validator #944

Open
wants to merge 23 commits into
base: philip/chaosplt-68
Choose a base branch
from

Conversation

ptnapoleon
Copy link
Contributor

@ptnapoleon ptnapoleon commented Dec 18, 2024

What does this PR do?

  • Adds new functionality
  • Alters existing functionality
  • Fixes a bug
  • Improves documentation or testing

Please briefly describe your changes as well as the motivation behind them:

  • The kubebuilder struct annotations are only used to generate the CRD spec yaml, which is then validated by the k8s api.
  • We would like to validate these requirements against specs even w/o access to the CRD spec file or kubernetes, only making basic code calls to Spec.Validate(). We used to use ddmark, but now we replace that with go-validator, an MIT licensed open source package.
  • Supplements 100% of disruption (crons to come in another PR) Spec kubebuilder annotations with struct tags. Adds a validation of all struct tags to the Spec.Validate() function
  • Adds custom translations to improve error messages
  • Adds unit tests

Code Quality Checklist

  • The documentation is up to date.
  • My code is sufficiently commented and passes continuous integration checks.
  • I have signed my commit (see Contributing Docs).

Testing

  • I leveraged continuous integration testing
    • by depending on existing unit tests or end-to-end tests.
    • by adding new unit tests or end-to-end tests.
  • I manually tested the following steps:
    • x
    • locally.
    • as a canary deployment to a cluster.

vendor/golang.org/x/crypto/sha3/hashes.go Show resolved Hide resolved
vendor/github.com/leodido/go-urn/urn8141.go Show resolved Hide resolved
@@ -89,6 +94,7 @@ require (
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.29.0 // indirect
go.opentelemetry.io/otel/sdk v1.29.0 // indirect
golang.org/x/crypto v0.26.0 // indirect

Choose a reason for hiding this comment

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

Library Vulnerability

golang.org/x/crypto → 0.26.0

Suggested change
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/crypto vv0.31.0// indirect
Misuse of ServerConfig.PublicKeyCallback may cause authorization bypass in golang.org/x/crypto (...read more)

Applications and libraries which misuse the ServerConfig.PublicKeyCallback callback may be susceptible to an authorization bypass.

The documentation for ServerConfig.PublicKeyCallback says that "A call to this function does not guarantee that the key offered is in fact used to authenticate." Specifically, the SSH protocol allows clients to inquire about whether a public key is acceptable before proving control of the corresponding private key. PublicKeyCallback may be called with multiple keys, and the order in which the keys were provided cannot be used to infer which key the client successfully authenticated with, if any. Some applications, which store the key(s) passed to PublicKeyCallback (or derived information) and make security relevant determinations based on it once the connection is established, may make incorrect assumptions.

For example, an attacker may send public keys A and B, and then authenticate with A. PublicKeyCallback would be called only twice, first with A and then with B. A vulnerable application may then make authorization decisions based on key B for which the attacker does not actually control the private key.

Since this API is widely misused, as a partial mitigation golang.org/x/[email protected] enforces the property that, when successfully authenticating via public key, the last key passed to ServerConfig.PublicKeyCallback will be the key used to authenticate the connection. PublicKeyCallback will now be called multiple times with the same key, if necessary. Note that the client may still not control the last key passed to PublicKeyCallback if the connection is then authenticated with a different method, such as PasswordCallback, KeyboardInteractiveCallback, or NoClientAuth.

Users should be using the Extensions field of the Permissions return value from the various authentication callbacks to record data associated with the authentication attempt instead of referencing external state. Once the connection is established the state corresponding to the successful authentication attempt can be retrieved via the ServerConn.Permissions field. Note that some third-party libraries misuse the Permissions type by sharing it across authentication attempts; users of third-party libraries should refer to the relevant projects for guidance.

View in Datadog  Leave us feedback  Documentation

@ptnapoleon ptnapoleon mentioned this pull request Jan 8, 2025
13 tasks
@datadog-datadog-prod-us1
Copy link

datadog-datadog-prod-us1 bot commented Jan 8, 2025

Datadog Report

Branch report: philip/chaosplt-68-replace
Commit report: ad50a69
Test service: chaos-controller

✅ 0 Failed, 892 Passed, 8 Skipped, 15m 36.18s Total Time

api/v1beta1/validations.go Outdated Show resolved Hide resolved
api/v1beta1/validations.go Outdated Show resolved Hide resolved
api/v1beta1/validations.go Outdated Show resolved Hide resolved
api/v1beta1/validations.go Outdated Show resolved Hide resolved
@ptnapoleon ptnapoleon force-pushed the philip/chaosplt-68-replace branch from ecc7f5f to 5560558 Compare January 13, 2025 17:37
@@ -747,7 +751,7 @@ func (s DisruptionSpec) validateGlobalDisruptionScope(requireSelectors bool) (re
}
}

if s.GRPC != nil && s.Level != chaostypes.DisruptionLevelPod {
if s.GRPC != nil && s.Level == chaostypes.DisruptionLevelNode {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Turns out that the "defaults" aren't appropriately set when we directly call Spec.Validate(), so grpc didn't realize an empty string meant pods.

@ptnapoleon ptnapoleon marked this pull request as ready for review January 15, 2025 15:01
@ptnapoleon ptnapoleon requested a review from a team as a code owner January 15, 2025 15:01
Copy link
Contributor

@clairecng clairecng left a comment

Choose a reason for hiding this comment

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

lgtm!

api/v1beta1/validations.go Show resolved Hide resolved
api/v1beta1/validations.go Outdated Show resolved Hide resolved
@@ -110,6 +110,382 @@ var _ = Describe("Validator", func() {
JustBeforeEach(func() {
err = validator.Validate()
})

Describe("validating top-level spec", func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

in most of your cases, I think you could probably do a describeTable instead? I think it would take less lines to achieve the same result.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So true. i'l try

Copy link
Contributor

@aymericDD aymericDD left a comment

Choose a reason for hiding this comment

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

Nice 👌

api/v1beta1/validations.go Outdated Show resolved Hide resolved
api/v1beta1/validations.go Outdated Show resolved Hide resolved
@ptnapoleon ptnapoleon changed the title Replace ddmark with go-validator CHAOSPLT-68: Replace ddmark with go-validator Jan 15, 2025
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.

4 participants