8000 Add checks for templates by mahendraintelops · Pull Request #207 · intelops/compage · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add checks for templates #207

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

Merged
merged 20 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
0df55da
feat: added go git integration for templates check
mahendraintelops Mar 2, 2024
19214f2
feat: added go git based git dirty check
mahendraintelops Mar 2, 2024
fffb13a
fix: updated go modules
mahendraintelops Mar 15, 2024
138d9c5
feat: added oci registry pull and cosign verify mechanism
mahendraintelops Mar 17, 2024
288fbda
feat: added changes to read templates from version folder
mahendraintelops Mar 17, 2024
ff53cf0
feat: refer version from environment in start command
mahendraintelops Mar 17, 2024
8526a31
feat: add a way to read version in pullTemplates command
mahendraintelops Mar 17, 2024
05dd051
feat: added version in template files
mahendraintelops Mar 17, 2024
f703327
refactoring: renamed package to valid name
mahendraintelops Mar 17, 2024
7f7e64d
feat: added remaining languages support in oci pull
mahendraintelops Mar 17, 2024
9360a68
enhancement: added version to grpc api
mahendraintelops Mar 18, 2024
2a82d94
feat: add artifacts for all
mahendraintelops Apr 1, 2024
26395b1
enhancement: added cosign verify code for keyless signing
mahendraintelops Apr 1, 2024
76fcb40
enhancement: added new path for code in templates
mahendraintelops Apr 2, 2024
12c0c68
fix: go mod init
mahendraintelops Apr 2, 2024
e889f5a
fix: golang linting issues
mahendraintelops Apr 2, 2024
dc944b7
fix: added comments
mahendraintelops Apr 3, 2024
64c0bd4
fix: added new path
mahendraintelops Apr 3, 2024
ced1f8f
enhancement: added new path for code in templates
mahendraintelops Apr 2, 2024
1d96b03
fix: path
mahendraintelops Apr 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
22 changes: 11 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ jobs:
actions: read
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: recursive
token: ${{ secrets.GH_TOKEN }}
- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: '1.20'
go-version: '1.22'
cache-dependency-path: '**/go.sum'
- name: Build
run: |
go build -v ./...
- name: golangci-lint
run: |
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.52.2
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.57.2
golangci-lint run
- name: Install Protoc
uses: arduino/setup-protoc@v2
uses: arduino/setup-protoc@v3
with:
version: "23.x"
- name: Test
Expand All @@ -51,7 +51,7 @@ jobs:
go run main.go pullTemplates --all
go test -v ./... -race -coverprofile=coverage.out -coverpkg=./... -covermode=atomic
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
files: ./coverage.out
flags: core
Expand Down Expand Up @@ -83,14 +83,14 @@ jobs:
security-events: write
steps:
- name: Checkout GitHub Action
uses: actions/checkout@v3
uses: actions/checkout@v4
# setup Docker build action
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
- name: Docker metadata
id: metadata
uses: docker/metadata-action@v4
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ github.repository }}
tags: |
Expand All @@ -100,13 +100,13 @@ jobs:
flavor: |
latest=true
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GH_TOKEN }}
- name: Build image and push to GitHub Container Registry
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
# relative path to the place where source code with Dockerfile is located
context: .
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ jobs:
- name: Test environment variable
run: echo ${{ env.RELEASE_VERSION }}
- name: Check out GitHub repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: recursive
token: ${{ secrets.GH_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GH_TOKEN }}
- name: Build image and push to GitHub Container Registry
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
push: true
context: .
Expand Down Expand Up @@ -73,7 +73,7 @@ jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: 'recursive'
Expand All @@ -85,7 +85,7 @@ jobs:
run: |
# List all nested directories
find . -type f
- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: 1.21
cache: true
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ compage
dist/
/cosign.key
/cosign.pub
/myproject/*
myproject/*
cmd/artifacts/.DS_Store
/__debug_bin*
2 changes: 1 addition & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ signs:
- '--output-signature=${signature}'
- '${artifact}'
- "--yes"
artifacts: checksum
artifacts: all
output: true

changelog:
Expand Down
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"mode": "debug",
"program": "${workspaceRoot}/main.go",
"cwd": "${workspaceRoot}",
"args": ["init", "--language","dotnet"]
"args": ["pullTemplates"]
}
]
}
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ To contribute code.
## Regenerate the gRPC code from .proto files
- Install below packages to regenerate the gRPC code.
```shell
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
```
- Update below statement in ~/.zshrc or ~/.bashrc depending on the shell you are using.
```shell
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
proto:
if [ -d "gen/api/v1" ]; then rm -rf gen/api/v1; fi && mkdir -p ./gen && protoc --go_out=./gen --go-grpc_opt=paths=source_relative --go_opt=paths=source_relative --go-grpc_out=./gen api/v1/*.proto
15 changes: 8 additions & 7 deletions api/v1/project.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ service ProjectService {
}

message GenerateCodeRequest {
string projectName = 1;
string projectJSON = 2;
string gitRepositoryName = 3;
string gitPlatformName = 4;
string gitPlatformURL = 5;
string gitPlatformUserName = 6;
string projectMetadata = 7;
string projectVersion = 1;
string projectName = 2;
string projectJSON = 3;
string gitRepositoryName = 4;
string gitPlatformName = 5;
string gitPlatformURL = 6;
string gitPlatformUserName = 7;
string projectMetadata = 8;
}

message GenerateCodeResponse{
Expand Down
107 changes: 107 additions & 0 deletions cmd/artifacts/cosign/verifier.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package cosign

import (
"context"
"github.com/fatih/color"
"github.com/google/go-containerregistry/pkg/name"
artifactUtils "github.com/intelops/compage/cmd/artifacts/utils"
"github.com/sigstore/cosign/v2/cmd/cosign/cli/fulcio"
"github.com/sigstore/cosign/v2/cmd/cosign/cli/options"
"github.com/sigstore/cosign/v2/cmd/cosign/cli/rekor"
"github.com/sigstore/cosign/v2/cmd/cosign/cli/verify"
"github.com/sigstore/cosign/v2/pkg/cosign"
sig "github.com/sigstore/cosign/v2/pkg/signature"
"github.com/sigstore/sigstore/pkg/cryptoutils"
log "github.com/sirupsen/logrus"
)

func VerifyArtifact(ctx context.Context, key string) error {
artifactURL := ctx.Value(artifactUtils.ContextKeyArtifactURL).(string)
ref, err := name.ParseReference(artifactURL)
if err != nil {
log.Errorf("parsing reference: %v", err)
return err
}
chopts := &cosign.CheckOpts{
ClaimVerifier: cosign.SimpleClaimVerifier,
}
chopts.RekorClient, err = rekor.NewClient(options.DefaultRekorURL)
if err != nil {
log.Errorf("creating Rekor client: %v", err)
return err
}
chopts.RootCerts, err = fulcio.GetRoots()
if err != nil {
log.Errorf("getting Fulcio root certs: %v", err)
return err
}
ro := options.RegistryOptions{}
chopts.RegistryClientOpts, err = ro.ClientOpts(ctx)
if err != nil {
log.Errorf("getting registry client options: %v", err)
return err
}
chopts.IntermediateCerts, err = fulcio.GetIntermediates()
if err != nil {
log.Errorf("unable to get Fulcio intermediate certs: %s", err)
return err
}
// Check if PubKey is supplied
if key != "" {
pub, err := sig.LoadPublicKey(ctx, key)
if err != nil {
log.Errorf("Error loading Pub Key: %v", err)
return err
}
chopts.SigVerifier = pub
}
fulcioVerified := chopts.SigVerifier == nil
chopts.RekorPubKeys, err = cosign.GetRekorPubs(ctx)
if err != nil {
log.Errorf("unable to get Rekor public keys: %s", err)
return err
}
chopts.CTLogPubKeys, err = cosign.GetCTLogPubs(ctx)
if err != nil {
log.Errorf("unable to get CTLog public keys: %s", err)
return err
}
sigs, bundleVerified, err := cosign.VerifyImageSignatures(context.Background(), ref, chopts)
if err != nil {
log.Errorf("verifying image signatures: %v", err)
return err
}

if bundleVerified {
verify.PrintVerificationHeader(ctx, ref.String(), chopts, bundleVerified, fulcioVerified)
for _, signature := range sigs {
if cert, err := signature.Cert(); err == nil && cert != nil {
ce := cosign.CertExtensions{Cert: cert}
sub := ""
if sans := cryptoutils.GetSubjectAlternateNames(cert); len(sans) > 0 {
sub = sans[0]
}
color.Green("Certificate subject: %s", sub)
if issuerURL := ce.GetIssuer(); issuerURL != "" {
color.Green("Certificate issuer URL: %s", issuerURL)
}
if githubWorkflowTrigger := ce.GetCertExtensionGithubWorkflowTrigger(); githubWorkflowTrigger != "" {
color.Green("GitHub Workflow Trigger: %s", githubWorkflowTrigger)
}
if githubWorkflowSha := ce.GetExtensionGithubWorkflowSha(); githubWorkflowSha != "" {
color.Green("GitHub Workflow SHA: %s", githubWorkflowSha)
}
if githubWorkflowName := ce.GetCertExtensionGithubWorkflowName(); githubWorkflowName != "" {
color.Green("GitHub Workflow Name: %s", githubWorkflowName)
}
if githubWorkflowRepository := ce.GetCertExtensionGithubWorkflowRepository(); githubWorkflowRepository != "" {
color.Green("GitHub Workflow Repository: %s", githubWorkflowRepository)
}
if githubWorkflowRef := ce.GetCertExtensionGithubWorkflowRef(); githubWorkflowRef != "" {
color.Green("GitHub Workflow Ref: %s", githubWorkflowRef)
}
}
}
}
return nil
}
Loading
0