Skip to content

Reject bootstrap CA files without certificates - #6160

Open
sarankumar1325 wants to merge 1 commit into
fluxcd:mainfrom
sarankumar1325:validate-bootstrap-ca-file
Open

sarankumar1325 wants to merge 1 commit into
fluxcd:mainfrom
sarankumar1325:validate-bootstrap-ca-file

Conversation

@sarankumar1325

Copy link
Copy Markdown

flux bootstrap read --ca-file without checking what was in it. If the file had no PEM certificates (wrong path to a key or DER file, empty file, bad copy), AppendCertsFromPEM in the provider transport returned false and the result was ignored. The command then failed later with a generic x509: certificate signed by unknown authority error, which doesn't point at the CA file. The same bytes were also used as ca.crt for the Git source secret.

This adds a readCAFile helper in cmd/flux/bootstrap.go. It reads the file and checks that it has at least one PEM certificate. The five bootstrap commands (git, github, gitlab, gitea, bitbucket-server) now use it instead of their copies of os.ReadFile. The error for a file that can't be read stays the same.

Tests: TestReadCAFile covers a valid CA file, a missing file, an empty file and non-PEM content. I ran go test ./cmd/flux/ -run 'TestReadCAFile|TestBootstrapValidate', go vet (no tags, unit and e2e) and gofmt.

AI disclosure: prepared with an AI assistant (Grok Bot), following AGENTS.md. I reviewed the change.

flux bootstrap read --ca-file without checking its contents. A file
with no PEM certificates was silently ignored by the provider client,
which then failed later with an unknown authority error, and the
file was still written to the cluster as the Git source CA.

Check that the file contains at least one PEM certificate and fail
early with a clear error.

Signed-off-by: Saran Kumar <120080287+sarankumar1325@users.noreply.github.com>
Assisted-by: Grok Bot/grok

This branch has not been deployed

No deployments
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.

1 participant