Skip to content

CLOUDP-315271: Onboard Kundukto to CI #3862

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

Open
wants to merge 17 commits into
base: CLOUDP-227276_ssdlc_phase_2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*.so
*.dylib
bin/**
compliance/**
dist/**
# mac notarization service
linux_amd64/**
Expand Down
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ addcopy: ## Add missing license to files
@scripts/add-copy.sh

.PHONY: generate
generate: gen-docs gen-mocks gen-api-commands ## Generate docs, mocks, code, api commands, all auto generated assets
generate: gen-docs gen-mocks gen-api-commands gen-purls ## Generate docs, mocks, code, api commands, all auto generated assets

.PHONY: apply-overlay
apply-overlay: ## Apply overlay on openapi spec
Expand Down Expand Up @@ -149,6 +149,14 @@ gen-docs: gen-docs-metadata ## Generate docs for atlascli commands
@echo "==> Generating docs"
go run -ldflags "$(LINKER_FLAGS)" ./tools/cmd/docs

.PHONY: gen-purls
gen-purls: # Generate purls on linux os
Copy link
Collaborator

Choose a reason for hiding this comment

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

will hooking this to the pre commit be a separate task?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I didn't intended to since, as a part of CI, we do a check to see if purls.txt is up-to-date. Devs would have to manually run this command. My intent here was to give devs visual on changes to sbom because of their work.

I'm happy to include this command in pre commit. To verify @gssbzn, this would make the CI check is redundant, correct?

Copy link
Collaborator

Choose a reason for hiding this comment

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

this would make the CI check is redundant, correct?

No cause having the pre commit installed is opt-in, and you can also do git commit --no-verify so you still need to check the files is up to date on the CI

Also just inc ase, ideally this should only run if the go.mod is modified

@echo "==> Generating purls"
GOOS=linux GOARCH=amd64 go build -trimpath -mod=readonly -o bin/atlas-linux ./cmd/atlas
Copy link
Collaborator

Choose a reason for hiding this comment

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

why hardcode to linux?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

there are some dependencies which are used only by some builds. For the moment, we will only generate purls for linux (in the interest of reducing this PRs scope) and will include generation for all builds, compiling them into one list which will be used for sbom generation in CLOUDP-316920

go version -m ./bin/atlas-linux | \
awk '$$1 == "dep" || $$1 == "=>" { print "pkg:golang/" $$2 "@" $$3 }' | \
LC_ALL=C sort > build/package/purls.txt

.PHONY: build
build: ## Generate an atlas binary in ./bin
@echo "==> Building $(ATLAS_BINARY_NAME) binary"
Expand Down
23 changes: 23 additions & 0 deletions build/ci/check-purls.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

# Copyright 2025 MongoDB Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -Eeou pipefail

if ! git diff --quiet --exit-code build/package/purls.txt; then
echo "build/package/purls.txt is out of date. Please run 'make gen-purls' and commit the result."
git --no-pager diff build/package/purls.txt
exit 1
fi
19 changes: 19 additions & 0 deletions build/ci/evergreen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,21 @@ functions:
binary: make
args:
- otel
"check purls":
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

- command: subprocess.exec
type: test
params:
<<: *go_options
binary: make
args:
- gen-purls
- command: subprocess.exec
params:
<<: *go_options
include_expansions_in_env:
- workdir
binary: build/ci/check-purls.sh

tasks:
- name: compile
tags: ["code_health"]
Expand Down Expand Up @@ -1726,6 +1741,10 @@ tasks:
vars:
span: "coverage"
attr: "total=${percentage},count=${count}"
- name: check_purls
tags: ["code_health"]
commands:
- func: "check purls"
- name: snyk_monitor
tags:
- snyk
Expand Down
58 changes: 58 additions & 0 deletions build/ci/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,48 @@ functions:
params:
<<: *go_options
binary: build/package/generate-notices.sh
"generate sbom":
- command: ec2.assume_role
params:
role_arn: ${ecr_role_arn}
- command: subprocess.exec
params:
<<: *go_options
include_expansions_in_env:
- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY
- AWS_SESSION_TOKEN
- workdir
binary: build/package/generate-sbom.sh
"run silkbomb":
- command: ec2.assume_role
params:
role_arn: ${kondukto_role_arn}
- command: shell.exec
params:
silent: true
shell: bash
include_expansions_in_env: [AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN]
script: |
set -e
kondukto_token=$(aws secretsmanager get-secret-value --secret-id "kondukto-token" --region "us-east-1" --query 'SecretString' --output text)
echo "KONDUKTO_TOKEN=$kondukto_token" > ${workdir}/kondukto_credentials.env
- command: shell.exec
params:
shell: bash
script: |
docker run \
--pull=always \
--platform="linux/amd64" \
--rm \
--env-file ${workdir}/kondukto_credentials.env \
-v ${workdir}:/workdir \
901841024863.dkr.ecr.us-east-1.amazonaws.com/release-infrastructure/silkbomb:2.0 \
upload \
--sbom-in /workdir/src/github.com/mongodb/mongodb-atlas-cli/compliance/sbom.json \
--repo mongodb_mongodb-atlas-cli \
--branch ${branch_name}
rm ${workdir}/kondukto_credentials.env
"package":
- command: github.generate_token
params:
Expand Down Expand Up @@ -317,6 +359,10 @@ tasks:
permissions: public-read
content_type: ${content_type|application/octet-stream}
display_name: unsigned
- name: generate_and_upload_sbom
commands:
- func: "generate sbom"
- func: "run silkbomb"
- name: package_goreleaser
tags: ["packaging"]
depends_on:
Expand Down Expand Up @@ -528,6 +574,8 @@ buildvariants:
depends_on:
- name: package_msi
variant: "go_atlascli_msi_snapshot"
- name: generate_and_upload_sbom
variant: ssdlc
- name: publish_atlascli_snapshot
display_name: "Publish AtlasCLI Snapshot"
run_on:
Expand All @@ -553,6 +601,8 @@ buildvariants:
depends_on:
- name: package_msi
variant: release_atlascli_msi
- name: generate_and_upload_sbom
variant: ssdlc
- name: copybara
display_name: "Copybara"
git_tag_only: true
Expand Down Expand Up @@ -605,3 +655,11 @@ buildvariants:
- ubuntu2004-small
tasks:
- name: .smoke-test .generate .repo .atlascli
- name: ssdlc
display_name: Compliance [ssdlc]
run_on:
- ubuntu2204-small
expansions:
<<: *go_linux_version
tasks:
- name: generate_and_upload_sbom
3 changes: 2 additions & 1 deletion build/package/.goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,5 @@ release:
name_template: "MongoDB Atlas CLI {{.Version}}"
extra_files:
- glob: ./bin/*.msi
version: 2
- glob: compliance/**/*
version: 2
31 changes: 31 additions & 0 deletions build/package/generate-sbom.sh
Copy link
Collaborator

Choose a reason for hiding this comment

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

general design comment, can we commit the purl file and make it a CI check (GH or EVG no preference) that is kept up to date, this is similar to how other repos manage this file

Copy link
Collaborator

Choose a reason for hiding this comment

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

check the library owners check which is kind of similar

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would't go for this approach we would jump from 2 files storing dependency information (library_owners.json and go.mod) to 3 files (library_owners.json, go.mod and purls.txt).

I would prefer for the tooling to translate dependencies into purls and later json on the fly as needed.

I'm inclined to even remove library_owners.json, given only our team has code in atlasCLI since the kubernetes plugin extraction.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm ok to remove lib owners (same reason) but I see value on purls being committed given shipped dependencies are not the same as the ones in go.mod and this raises awareness when adding new libs and the implications, this also comes with the comment that I'd like if purls are auto generated by the precommit hook, similar to mms

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have no strong opinion here. Having the purl file committed could definitely help with making dependencies more visible, but I see @fmenezes's point about not wanting to manage yet another file.

I can create a make command to generate purls from the binary and set up a GH action to check that it's up-to-date similar to how we do the docs check.

@fmenezes, any strong feelings about this idea?

Copy link
Collaborator

Choose a reason for hiding this comment

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

sure that is fine, we can commit it but bear in mind the extra checks

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

# Copyright 2025 MongoDB Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -Eeou pipefail

export WORKDIR=${workdir:?}

# Authenticate Docker to AWS ECR
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 901841024863.dkr.ecr.us-east-1.amazonaws.com

echo "Generating SBOMs..."
docker run --rm \
-v "$WORKDIR/src/github.com/mongodb/mongodb-atlas-cli:/pwd" \
901841024863.dkr.ecr.us-east-1.amazonaws.com/release-infrastructure/silkbomb:2.0 \
update \
--purls /pwd/build/package/purls.txt \
--sbom-out /pwd/sbom.json

122 changes: 122 additions & 0 deletions build/package/purls.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
pkg:golang/cloud.google.com/go/auth/[email protected]
pkg:golang/cloud.google.com/go/[email protected]
pkg:golang/cloud.google.com/go/compute/[email protected]
pkg:golang/cloud.google.com/go/[email protected]
pkg:golang/cloud.google.com/go/[email protected]
pkg:golang/cloud.google.com/go/[email protected]
pkg:golang/github.com/AlecAivazis/survey/[email protected]
pkg:golang/github.com/Azure/azure-sdk-for-go/sdk/[email protected]
pkg:golang/github.com/Azure/azure-sdk-for-go/sdk/[email protected]
pkg:golang/github.com/Azure/azure-sdk-for-go/sdk/[email protected]
pkg:golang/github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/[email protected]
pkg:golang/github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/[email protected]
pkg:golang/github.com/AzureAD/[email protected]
pkg:golang/github.com/Masterminds/semver/[email protected]
pkg:golang/github.com/PaesslerAG/[email protected]
pkg:golang/github.com/PaesslerAG/[email protected]
pkg:golang/github.com/ProtonMail/[email protected]
pkg:golang/github.com/STARRY-S/[email protected]
pkg:golang/github.com/andybalholm/[email protected]
pkg:golang/github.com/aws/aws-sdk-go-v2/[email protected]
pkg:golang/github.com/aws/aws-sdk-go-v2/[email protected]
pkg:golang/github.com/aws/aws-sdk-go-v2/feature/ec2/[email protected]
pkg:golang/github.com/aws/aws-sdk-go-v2/internal/[email protected]
pkg:golang/github.com/aws/aws-sdk-go-v2/internal/endpoints/[email protected]
pkg:golang/github.com/aws/aws-sdk-go-v2/internal/[email protected]
pkg:golang/github.com/aws/aws-sdk-go-v2/service/internal/[email protected]
pkg:golang/github.com/aws/aws-sdk-go-v2/service/internal/[email protected]
pkg:golang/github.com/aws/aws-sdk-go-v2/service/[email protected]
pkg:golang/github.com/aws/aws-sdk-go-v2/service/[email protected]
pkg:golang/github.com/aws/aws-sdk-go-v2/service/[email protected]
pkg:golang/github.com/aws/aws-sdk-go-v2/service/[email protected]
pkg:golang/github.com/aws/[email protected]
pkg:golang/github.com/aws/[email protected]
pkg:golang/github.com/bodgit/[email protected]
pkg:golang/github.com/bodgit/[email protected]
pkg:golang/github.com/bodgit/[email protected]
pkg:golang/github.com/briandowns/[email protected]
pkg:golang/github.com/cloudflare/[email protected]
pkg:golang/github.com/denisbrodbeck/[email protected]
pkg:golang/github.com/dsnet/[email protected]
pkg:golang/github.com/fatih/[email protected]
pkg:golang/github.com/felixge/[email protected]
pkg:golang/github.com/fsnotify/[email protected]
pkg:golang/github.com/go-logr/[email protected]
pkg:golang/github.com/go-logr/[email protected]
pkg:golang/github.com/go-viper/mapstructure/[email protected]
pkg:golang/github.com/golang-jwt/jwt/[email protected]
pkg:golang/github.com/golang/[email protected]
pkg:golang/github.com/golang/[email protected]
pkg:golang/github.com/google/go-github/[email protected]
pkg:golang/github.com/google/[email protected]
pkg:golang/github.com/google/[email protected]
pkg:golang/github.com/google/[email protected]
pkg:golang/github.com/googleapis/[email protected]
pkg:golang/github.com/googleapis/gax-go/[email protected]
pkg:golang/github.com/hashicorp/[email protected]
pkg:golang/github.com/hashicorp/[email protected]
pkg:golang/github.com/hashicorp/golang-lru/[email protected]
pkg:golang/github.com/iancoleman/[email protected]
pkg:golang/github.com/kballard/[email protected]
pkg:golang/github.com/klauspost/[email protected]
pkg:golang/github.com/klauspost/[email protected]
pkg:golang/github.com/kylelemons/[email protected]
pkg:golang/github.com/mattn/[email protected]
pkg:golang/github.com/mattn/[email protected]
pkg:golang/github.com/mgutz/[email protected]
pkg:golang/github.com/mholt/[email protected]
pkg:golang/github.com/minio/[email protected]
pkg:golang/github.com/mongodb-forks/[email protected]
pkg:golang/github.com/montanaflynn/[email protected]
pkg:golang/github.com/nwaples/rardecode/[email protected]
pkg:golang/github.com/pelletier/go-toml/[email protected]
pkg:golang/github.com/pelletier/[email protected]
pkg:golang/github.com/pierrec/lz4/[email protected]
pkg:golang/github.com/pkg/[email protected]
pkg:golang/github.com/sagikazarmark/[email protected]
pkg:golang/github.com/shirou/gopsutil/[email protected]
pkg:golang/github.com/sorairolake/[email protected]
pkg:golang/github.com/sourcegraph/[email protected]
pkg:golang/github.com/spf13/[email protected]
pkg:golang/github.com/spf13/[email protected]
pkg:golang/github.com/spf13/[email protected]
pkg:golang/github.com/spf13/[email protected]
pkg:golang/github.com/spf13/[email protected]
pkg:golang/github.com/subosito/[email protected]
pkg:golang/github.com/tangzero/[email protected]
pkg:golang/github.com/therootcompany/[email protected]
pkg:golang/github.com/tklauser/[email protected]
pkg:golang/github.com/tklauser/[email protected]
pkg:golang/github.com/ulikunitz/[email protected]
pkg:golang/github.com/xdg-go/[email protected]
pkg:golang/github.com/xdg-go/[email protected]
pkg:golang/github.com/xdg-go/[email protected]
pkg:golang/github.com/youmark/[email protected]
pkg:golang/go.mongodb.org/atlas-sdk/[email protected]
pkg:golang/go.mongodb.org/atlas-sdk/[email protected]
pkg:golang/go.mongodb.org/[email protected]
pkg:golang/go.mongodb.org/[email protected]
pkg:golang/go.opentelemetry.io/auto/[email protected]
pkg:golang/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/[email protected]
pkg:golang/go.opentelemetry.io/contrib/instrumentation/net/http/[email protected]
pkg:golang/go.opentelemetry.io/otel/[email protected]
pkg:golang/go.opentelemetry.io/otel/[email protected]
pkg:golang/go.opentelemetry.io/[email protected]
pkg:golang/[email protected]
pkg:golang/golang.org/x/[email protected]
pkg:golang/golang.org/x/[email protected]
pkg:golang/golang.org/x/[email protected]
pkg:golang/golang.org/x/[email protected]
pkg:golang/golang.org/x/[email protected]
pkg:golang/golang.org/x/[email protected]
pkg:golang/golang.org/x/[email protected]
pkg:golang/golang.org/x/[email protected]
pkg:golang/golang.org/x/[email protected]
pkg:golang/golang.org/x/[email protected]
pkg:golang/google.golang.org/[email protected]
pkg:golang/google.golang.org/genproto/googleapis/[email protected]
pkg:golang/google.golang.org/genproto/googleapis/[email protected]
pkg:golang/google.golang.org/[email protected]
pkg:golang/google.golang.org/[email protected]
pkg:golang/google.golang.org/[email protected]
pkg:golang/gopkg.in/[email protected]
7 changes: 7 additions & 0 deletions scripts/pre-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ if [[ -n "${STAGED_GO_FILES}" ]]; then
git add docs
fi

STAGED_GO_MOD_FILES=$(git diff --cached --name-only | grep -E "^go\.(mod|sum)$" || true)

if [[ -n "${STAGED_GO_MOD_FILES}" ]]; then
make gen-purls > /dev/null
git add build/package/purls.txt
fi

STAGED_EVG_FILES=$(git diff --cached --name-only | grep "evergreen.yml$")

for FILE in ${STAGED_EVG_FILES}
Expand Down
Loading