-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from pluralsh/master
Initial changes
- Loading branch information
Showing
13 changed files
with
432 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: CI | ||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
env: | ||
GOPATH: /home/runner/go/ | ||
GOPROXY: "https://proxy.golang.org" | ||
jobs: | ||
build-kas: | ||
name: Build kas | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-go@v4 | ||
with: | ||
go-version-file: go.mod | ||
check-latest: true | ||
- run: TARGET_DIRECTORY=. make kas | ||
build-agentk: | ||
name: Build agentk | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-go@v4 | ||
with: | ||
go-version-file: go.mod | ||
check-latest: true | ||
- run: TARGET_DIRECTORY=. make agentk | ||
lint: | ||
name: Lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-go@v4 | ||
with: | ||
go-version-file: go.mod | ||
check-latest: true | ||
- uses: golangci/golangci-lint-action@v3 | ||
with: | ||
version: latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: Trivy | ||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
branches: | ||
- main | ||
push: | ||
branches: | ||
- main | ||
schedule: | ||
- cron: "0 0 * * *" | ||
jobs: | ||
trivy-scan: | ||
name: Trivy IaC scan | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
security-events: write | ||
actions: read | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
- name: Run Trivy vulnerability scanner in IaC mode | ||
uses: aquasecurity/trivy-action@master | ||
with: | ||
scan-type: 'fs' | ||
hide-progress: false | ||
scan-ref: '.' | ||
format: 'sarif' | ||
output: 'trivy-results.sarif' | ||
scanners: 'vuln,secret,config' | ||
ignore-unfixed: true | ||
- name: Upload Trivy scan results to GitHub Security tab | ||
uses: github/codeql-action/upload-sarif@v2 | ||
with: | ||
sarif_file: 'trivy-results.sarif' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,8 @@ go_build_kas* | |
.DS_Store | ||
|
||
# settings for Jetbrains Goland | ||
.idea | ||
.idea | ||
|
||
# Dist binaries | ||
agentk | ||
kas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM golang:1.21 | ||
|
||
WORKDIR /usr/src/app | ||
|
||
# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change | ||
COPY go.mod go.sum ./ | ||
RUN go mod download && go mod verify | ||
|
||
COPY . . | ||
RUN go build \ | ||
-o /usr/local/bin/app ./cmd/kas | ||
|
||
CMD ["app"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package fake | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
|
||
grpc_auth "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/auth" | ||
"go.uber.org/zap" | ||
|
||
"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/internal/api" | ||
fake "gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/internal/fake/api" | ||
"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/internal/gitlab" | ||
"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/internal/module/modserver" | ||
"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/internal/tool/cache" | ||
) | ||
|
||
type ServerAgentRpcApi struct { | ||
modserver.RpcApi | ||
Token api.AgentToken | ||
AgentInfoCache *cache.CacheWithErr[api.AgentToken, *api.AgentInfo] | ||
agentIdAttrOnce sync.Once | ||
} | ||
|
||
func (a *ServerAgentRpcApi) AgentToken() api.AgentToken { | ||
return a.Token | ||
} | ||
|
||
func (a *ServerAgentRpcApi) AgentInfo(ctx context.Context, log *zap.Logger) (*api.AgentInfo, error) { | ||
return a.getAgentInfoCached(ctx) | ||
} | ||
|
||
func (a *ServerAgentRpcApi) getAgentInfoCached(ctx context.Context) (*api.AgentInfo, error) { | ||
return a.AgentInfoCache.GetItem(ctx, a.Token, func() (*api.AgentInfo, error) { | ||
return fake.GetAgentInfo(ctx, a.Token, gitlab.WithoutRetries()) | ||
}) | ||
} | ||
|
||
type ServerAgentRpcApiFactory struct { | ||
RPCApiFactory modserver.RpcApiFactory | ||
AgentInfoCache *cache.CacheWithErr[api.AgentToken, *api.AgentInfo] | ||
} | ||
|
||
func (f *ServerAgentRpcApiFactory) New(ctx context.Context, fullMethodName string) (modserver.AgentRpcApi, error) { | ||
token, err := grpc_auth.AuthFromMD(ctx, "bearer") | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &ServerAgentRpcApi{ | ||
RpcApi: f.RPCApiFactory(ctx, fullMethodName), | ||
Token: api.AgentToken(token), | ||
AgentInfoCache: f.AgentInfoCache, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package api | ||
|
||
import ( | ||
"context" | ||
|
||
"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/pkg/entity" | ||
|
||
"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/internal/api" | ||
"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/internal/gitlab" | ||
) | ||
|
||
const ( | ||
AgentInfoApiPath = "/api/v4/internal/kubernetes/agent_info" | ||
) | ||
|
||
func GetAgentInfo(ctx context.Context, agentToken api.AgentToken, opts ...gitlab.DoOption) (*api.AgentInfo, error) { | ||
return &api.AgentInfo{ | ||
Id: 123456, | ||
ProjectId: 0, | ||
Name: "fake-agent", | ||
Repository: nil, | ||
DefaultBranch: "", | ||
GitalyInfo: &entity.GitalyInfo{ | ||
Address: "127.0.0.1", | ||
Token: "123", | ||
Features: nil, | ||
}, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.