From 7d0d11a45906961080aa72865532716647ee8d90 Mon Sep 17 00:00:00 2001 From: Mattia Buccarella Date: Mon, 6 Nov 2023 17:10:43 +0100 Subject: [PATCH 1/4] feat(runner): Integrate runner for Jenkins jobs Signed-off-by: Mattia Buccarella --- .../workflowcontract/v1/crafting_schema.pb.go | 1 + internal/attestation/crafter/runner.go | 2 + .../attestation/crafter/runners/generic.go | 2 + .../attestation/crafter/runners/jenkinsjob.go | 65 +++++++++ .../crafter/runners/jenkinsjob_test.go | 123 ++++++++++++++++++ 5 files changed, 193 insertions(+) create mode 100644 internal/attestation/crafter/runners/jenkinsjob.go create mode 100644 internal/attestation/crafter/runners/jenkinsjob_test.go diff --git a/app/controlplane/api/workflowcontract/v1/crafting_schema.pb.go b/app/controlplane/api/workflowcontract/v1/crafting_schema.pb.go index 0b782cf74..3de6c8f60 100644 --- a/app/controlplane/api/workflowcontract/v1/crafting_schema.pb.go +++ b/app/controlplane/api/workflowcontract/v1/crafting_schema.pb.go @@ -43,6 +43,7 @@ const ( CraftingSchema_Runner_GITHUB_ACTION CraftingSchema_Runner_RunnerType = 1 CraftingSchema_Runner_GITLAB_PIPELINE CraftingSchema_Runner_RunnerType = 2 CraftingSchema_Runner_AZURE_PIPELINE CraftingSchema_Runner_RunnerType = 3 + CraftingSchema_Runner_JENKINS_JOB CraftingSchema_Runner_RunnerType = 4 ) // Enum value maps for CraftingSchema_Runner_RunnerType. diff --git a/internal/attestation/crafter/runner.go b/internal/attestation/crafter/runner.go index a052c179b..3ae9393c2 100644 --- a/internal/attestation/crafter/runner.go +++ b/internal/attestation/crafter/runner.go @@ -44,6 +44,8 @@ func NewRunner(t schemaapi.CraftingSchema_Runner_RunnerType) supportedRunner { return &runners.GitlabPipeline{} case schemaapi.CraftingSchema_Runner_AZURE_PIPELINE: return &runners.AzurePipeline{} + case schemaapi.CraftingSchema_Runner_JENKINS_JOB: + return &runners.JenkinsJob{} default: return &runners.Generic{} } diff --git a/internal/attestation/crafter/runners/generic.go b/internal/attestation/crafter/runners/generic.go index ffa87b3bf..d47522012 100644 --- a/internal/attestation/crafter/runners/generic.go +++ b/internal/attestation/crafter/runners/generic.go @@ -27,6 +27,8 @@ func (r *Generic) CheckEnv() bool { return true } +// Returns a list of environment variables names. This list is used to +// automatically inject environment variables into the attestation. func (r *Generic) ListEnvVars() []string { return []string{} } diff --git a/internal/attestation/crafter/runners/jenkinsjob.go b/internal/attestation/crafter/runners/jenkinsjob.go new file mode 100644 index 000000000..410cd5a1f --- /dev/null +++ b/internal/attestation/crafter/runners/jenkinsjob.go @@ -0,0 +1,65 @@ +// +// Copyright 2023 The Chainloop Authors. +// +// 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. + +package runners + +import "os" + +type JenkinsJob struct{} + +const JenkinsJobID = "jenkins-job" + +func NewJenkinsJob() *JenkinsJob { + return &JenkinsJob{} +} + +// Checks whether we are within a Jenkins job +func (r *JenkinsJob) CheckEnv() bool { + for _, envVarName := range []string{"JENKINS_HOME", "BUILD_URL"} { + if os.Getenv(envVarName) == "" { + return false + } + } + + return true +} + +func (r *JenkinsJob) ListEnvVars() []string { + return []string{ + // Some info about the job + "JOB_NAME", + "BUILD_URL", + + // Some info about the commit (Jenkins Git Plugin) + "GIT_BRANCH", + "GIT_COMMIT", + + // Some info about the agent + "AGENT_WORKDIR", + "NODE_NAME", + } +} + +func (r *JenkinsJob) ResolveEnvVars() map[string]string { + return resolveEnvVars(r.ListEnvVars()) +} + +func (r *JenkinsJob) String() string { + return JenkinsJobID +} + +func (r *JenkinsJob) RunURI() string { + return os.Getenv("BUILD_URL") +} diff --git a/internal/attestation/crafter/runners/jenkinsjob_test.go b/internal/attestation/crafter/runners/jenkinsjob_test.go new file mode 100644 index 000000000..c36acc082 --- /dev/null +++ b/internal/attestation/crafter/runners/jenkinsjob_test.go @@ -0,0 +1,123 @@ +// +// Copyright 2023 The Chainloop Authors. +// +// 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. + +package runners + +import ( + "os" + "testing" + + "github.com/stretchr/testify/suite" +) + +type jenkinsJobSuite struct { + suite.Suite + runner *JenkinsJob +} + +func (s *jenkinsJobSuite) TestCheckEnv() { + testCases := []struct { + name string + env map[string]string + want bool + }{ + { + name: "empty", + env: map[string]string{}, + want: false, + }, + { + name: "missing JENKINS_HOME", + env: map[string]string{ + "BUILD_URL": "http://some-build-url/", + }, + want: false, + }, + { + name: "missing BUILD_URL", + env: map[string]string{ + "JENKINS_HOME": "http://some-jenkins-home/", + }, + want: false, + }, + { + name: "all present", + env: map[string]string{ + "BUILD_URL": "http://some-build-url/", + "JENKINS_HOME": "http://some-jenkins-home/", + }, + want: true, + }, + } + + for _, tc := range testCases { + s.T().Run(tc.name, func(t *testing.T) { + os.Unsetenv("BUILD_URL") + os.Unsetenv("JENKINS_HOME") + + for k, v := range tc.env { + t.Setenv(k, v) + } + + s.Equal(tc.want, s.runner.CheckEnv()) + }) + } +} + +func (s *jenkinsJobSuite) TestListEnvVars() { + s.Equal([]string{ + "JOB_NAME", + "BUILD_URL", + "GIT_BRANCH", + "GIT_COMMIT", + "AGENT_WORKDIR", + "NODE_NAME", + }, s.runner.ListEnvVars()) +} + +func (s *jenkinsJobSuite) TestResolveEnvVars() { + s.Equal(jenkinsJobTestingEnvVars, s.runner.ResolveEnvVars()) +} + +func (s *jenkinsJobSuite) TestRunURI() { + s.Equal("http://some-build-url/", s.runner.RunURI()) +} + +func (s *jenkinsJobSuite) TestRunnerName() { + s.Equal("jenkins-job", s.runner.String()) +} + +// Run before each test +func (s *jenkinsJobSuite) SetupTest() { + s.runner = NewJenkinsJob() + t := s.T() + for k, v := range jenkinsJobTestingEnvVars { + t.Setenv(k, v) + } +} + +var jenkinsJobTestingEnvVars = map[string]string{ + "JOB_NAME": "some-jenkins-job", + "BUILD_URL": "http://some-build-url/", + "GIT_BRANCH": "some-branch", + "GIT_COMMIT": "123", + "AGENT_WORKDIR": "/home/sample/agent", + "NODE_NAME": "some-node", +} + +// Run the tests +func TestJenkinsJobRunner(t *testing.T) { + suite.Run(t, new(jenkinsJobSuite)) +} From bff897f1517e2e6ae3f751cc149dd24229438101 Mon Sep 17 00:00:00 2001 From: Mattia Buccarella Date: Fri, 3 Nov 2023 14:51:07 +0100 Subject: [PATCH 2/4] fix: adding new runner type by changing the proto Signed-off-by: Mattia Buccarella --- .../workflowcontract/v1/crafting_schema.ts | 6 ++ .../workflowcontract/v1/crafting_schema.pb.go | 91 ++++++++++--------- .../workflowcontract/v1/crafting_schema.proto | 1 + 3 files changed, 54 insertions(+), 44 deletions(-) diff --git a/app/controlplane/api/gen/frontend/workflowcontract/v1/crafting_schema.ts b/app/controlplane/api/gen/frontend/workflowcontract/v1/crafting_schema.ts index 182e67a75..7023b9574 100644 --- a/app/controlplane/api/gen/frontend/workflowcontract/v1/crafting_schema.ts +++ b/app/controlplane/api/gen/frontend/workflowcontract/v1/crafting_schema.ts @@ -30,6 +30,7 @@ export enum CraftingSchema_Runner_RunnerType { GITHUB_ACTION = 1, GITLAB_PIPELINE = 2, AZURE_PIPELINE = 3, + JENKINS_JOB = 4, UNRECOGNIZED = -1, } @@ -47,6 +48,9 @@ export function craftingSchema_Runner_RunnerTypeFromJSON(object: any): CraftingS case 3: case "AZURE_PIPELINE": return CraftingSchema_Runner_RunnerType.AZURE_PIPELINE; + case 4: + case "JENKINS_JOB": + return CraftingSchema_Runner_RunnerType.JENKINS_JOB; case -1: case "UNRECOGNIZED": default: @@ -64,6 +68,8 @@ export function craftingSchema_Runner_RunnerTypeToJSON(object: CraftingSchema_Ru return "GITLAB_PIPELINE"; case CraftingSchema_Runner_RunnerType.AZURE_PIPELINE: return "AZURE_PIPELINE"; + case CraftingSchema_Runner_RunnerType.JENKINS_JOB: + return "JENKINS_JOB"; case CraftingSchema_Runner_RunnerType.UNRECOGNIZED: default: return "UNRECOGNIZED"; diff --git a/app/controlplane/api/workflowcontract/v1/crafting_schema.pb.go b/app/controlplane/api/workflowcontract/v1/crafting_schema.pb.go index 3de6c8f60..d105d45de 100644 --- a/app/controlplane/api/workflowcontract/v1/crafting_schema.pb.go +++ b/app/controlplane/api/workflowcontract/v1/crafting_schema.pb.go @@ -43,7 +43,7 @@ const ( CraftingSchema_Runner_GITHUB_ACTION CraftingSchema_Runner_RunnerType = 1 CraftingSchema_Runner_GITLAB_PIPELINE CraftingSchema_Runner_RunnerType = 2 CraftingSchema_Runner_AZURE_PIPELINE CraftingSchema_Runner_RunnerType = 3 - CraftingSchema_Runner_JENKINS_JOB CraftingSchema_Runner_RunnerType = 4 + CraftingSchema_Runner_JENKINS_JOB CraftingSchema_Runner_RunnerType = 4 ) // Enum value maps for CraftingSchema_Runner_RunnerType. @@ -53,12 +53,14 @@ var ( 1: "GITHUB_ACTION", 2: "GITLAB_PIPELINE", 3: "AZURE_PIPELINE", + 4: "JENKINS_JOB", } CraftingSchema_Runner_RunnerType_value = map[string]int32{ "RUNNER_TYPE_UNSPECIFIED": 0, "GITHUB_ACTION": 1, "GITLAB_PIPELINE": 2, "AZURE_PIPELINE": 3, + "JENKINS_JOB": 4, } ) @@ -441,7 +443,7 @@ var file_workflowcontract_v1_crafting_schema_proto_rawDesc = []byte{ 0x63, 0x68, 0x65, 0x6d, 0x61, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x13, 0x77, 0x6f, 0x72, 0x6b, 0x66, 0x6c, 0x6f, 0x77, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x2e, 0x76, 0x31, 0x1a, 0x17, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x65, 0x2f, 0x76, 0x61, 0x6c, 0x69, 0x64, - 0x61, 0x74, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xc6, 0x07, 0x0a, 0x0e, 0x43, 0x72, + 0x61, 0x74, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xd7, 0x07, 0x0a, 0x0e, 0x43, 0x72, 0x61, 0x66, 0x74, 0x69, 0x6e, 0x67, 0x53, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x12, 0x30, 0x0a, 0x0e, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x09, 0xfa, 0x42, 0x06, 0x72, 0x04, 0x0a, 0x02, 0x76, 0x31, 0x52, @@ -461,58 +463,59 @@ var file_workflowcontract_v1_crafting_schema_proto_rawDesc = []byte{ 0x6f, 0x6e, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x77, 0x6f, 0x72, 0x6b, 0x66, 0x6c, 0x6f, 0x77, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0b, 0x61, 0x6e, 0x6e, 0x6f, - 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x1a, 0xc4, 0x01, 0x0a, 0x06, 0x52, 0x75, 0x6e, 0x6e, + 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x1a, 0xd5, 0x01, 0x0a, 0x06, 0x52, 0x75, 0x6e, 0x6e, 0x65, 0x72, 0x12, 0x53, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x35, 0x2e, 0x77, 0x6f, 0x72, 0x6b, 0x66, 0x6c, 0x6f, 0x77, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x72, 0x61, 0x66, 0x74, 0x69, 0x6e, 0x67, 0x53, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x2e, 0x52, 0x75, 0x6e, 0x6e, 0x65, 0x72, 0x2e, 0x52, 0x75, 0x6e, 0x6e, 0x65, 0x72, 0x54, 0x79, 0x70, 0x65, 0x42, 0x08, 0xfa, 0x42, 0x05, 0x82, 0x01, 0x02, 0x20, - 0x00, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x22, 0x65, 0x0a, 0x0a, 0x52, 0x75, 0x6e, 0x6e, 0x65, + 0x00, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x22, 0x76, 0x0a, 0x0a, 0x52, 0x75, 0x6e, 0x6e, 0x65, 0x72, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1b, 0x0a, 0x17, 0x52, 0x55, 0x4e, 0x4e, 0x45, 0x52, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x11, 0x0a, 0x0d, 0x47, 0x49, 0x54, 0x48, 0x55, 0x42, 0x5f, 0x41, 0x43, 0x54, 0x49, 0x4f, 0x4e, 0x10, 0x01, 0x12, 0x13, 0x0a, 0x0f, 0x47, 0x49, 0x54, 0x4c, 0x41, 0x42, 0x5f, 0x50, 0x49, 0x50, 0x45, 0x4c, 0x49, 0x4e, 0x45, 0x10, 0x02, 0x12, 0x12, 0x0a, 0x0e, 0x41, 0x5a, - 0x55, 0x52, 0x45, 0x5f, 0x50, 0x49, 0x50, 0x45, 0x4c, 0x49, 0x4e, 0x45, 0x10, 0x03, 0x1a, 0xc1, - 0x03, 0x0a, 0x08, 0x4d, 0x61, 0x74, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x12, 0x57, 0x0a, 0x04, 0x74, - 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x39, 0x2e, 0x77, 0x6f, 0x72, 0x6b, - 0x66, 0x6c, 0x6f, 0x77, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x2e, 0x76, 0x31, 0x2e, - 0x43, 0x72, 0x61, 0x66, 0x74, 0x69, 0x6e, 0x67, 0x53, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x2e, 0x4d, - 0x61, 0x74, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x2e, 0x4d, 0x61, 0x74, 0x65, 0x72, 0x69, 0x61, 0x6c, - 0x54, 0x79, 0x70, 0x65, 0x42, 0x08, 0xfa, 0x42, 0x05, 0x82, 0x01, 0x02, 0x20, 0x00, 0x52, 0x04, - 0x74, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x09, 0x42, 0x10, 0xfa, 0x42, 0x0d, 0x72, 0x0b, 0x32, 0x09, 0x5e, 0x5b, 0x5c, 0x77, 0x7c, - 0x2d, 0x5d, 0x2b, 0x24, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x6f, 0x70, - 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x6f, 0x70, - 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x12, 0x16, 0x0a, 0x06, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, - 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x12, 0x41, - 0x0a, 0x0b, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x05, 0x20, - 0x03, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x77, 0x6f, 0x72, 0x6b, 0x66, 0x6c, 0x6f, 0x77, 0x63, 0x6f, - 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x6e, 0x6e, 0x6f, 0x74, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0b, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x73, 0x22, 0xbe, 0x01, 0x0a, 0x0c, 0x4d, 0x61, 0x74, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x54, 0x79, - 0x70, 0x65, 0x12, 0x1d, 0x0a, 0x19, 0x4d, 0x41, 0x54, 0x45, 0x52, 0x49, 0x41, 0x4c, 0x5f, 0x54, - 0x59, 0x50, 0x45, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, - 0x00, 0x12, 0x0a, 0x0a, 0x06, 0x53, 0x54, 0x52, 0x49, 0x4e, 0x47, 0x10, 0x01, 0x12, 0x13, 0x0a, - 0x0f, 0x43, 0x4f, 0x4e, 0x54, 0x41, 0x49, 0x4e, 0x45, 0x52, 0x5f, 0x49, 0x4d, 0x41, 0x47, 0x45, - 0x10, 0x02, 0x12, 0x0c, 0x0a, 0x08, 0x41, 0x52, 0x54, 0x49, 0x46, 0x41, 0x43, 0x54, 0x10, 0x03, - 0x12, 0x17, 0x0a, 0x13, 0x53, 0x42, 0x4f, 0x4d, 0x5f, 0x43, 0x59, 0x43, 0x4c, 0x4f, 0x4e, 0x45, - 0x44, 0x58, 0x5f, 0x4a, 0x53, 0x4f, 0x4e, 0x10, 0x04, 0x12, 0x12, 0x0a, 0x0e, 0x53, 0x42, 0x4f, - 0x4d, 0x5f, 0x53, 0x50, 0x44, 0x58, 0x5f, 0x4a, 0x53, 0x4f, 0x4e, 0x10, 0x05, 0x12, 0x0d, 0x0a, - 0x09, 0x4a, 0x55, 0x4e, 0x49, 0x54, 0x5f, 0x58, 0x4d, 0x4c, 0x10, 0x06, 0x12, 0x0b, 0x0a, 0x07, - 0x4f, 0x50, 0x45, 0x4e, 0x56, 0x45, 0x58, 0x10, 0x07, 0x12, 0x0c, 0x0a, 0x08, 0x43, 0x53, 0x41, - 0x46, 0x5f, 0x56, 0x45, 0x58, 0x10, 0x08, 0x12, 0x09, 0x0a, 0x05, 0x53, 0x41, 0x52, 0x49, 0x46, - 0x10, 0x09, 0x22, 0x46, 0x0a, 0x0a, 0x41, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x12, 0x22, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x0e, - 0xfa, 0x42, 0x0b, 0x72, 0x09, 0x32, 0x07, 0x5e, 0x5b, 0x5c, 0x77, 0x5d, 0x2b, 0x24, 0x52, 0x04, - 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x42, 0x4d, 0x5a, 0x4b, 0x67, 0x69, - 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x6c, 0x6f, - 0x6f, 0x70, 0x2d, 0x64, 0x65, 0x76, 0x2f, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x6c, 0x6f, 0x6f, 0x70, - 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x70, 0x6c, 0x61, 0x6e, - 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x77, 0x6f, 0x72, 0x6b, 0x66, 0x6c, 0x6f, 0x77, 0x63, 0x6f, - 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x33, + 0x55, 0x52, 0x45, 0x5f, 0x50, 0x49, 0x50, 0x45, 0x4c, 0x49, 0x4e, 0x45, 0x10, 0x03, 0x12, 0x0f, + 0x0a, 0x0b, 0x4a, 0x45, 0x4e, 0x4b, 0x49, 0x4e, 0x53, 0x5f, 0x4a, 0x4f, 0x42, 0x10, 0x04, 0x1a, + 0xc1, 0x03, 0x0a, 0x08, 0x4d, 0x61, 0x74, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x12, 0x57, 0x0a, 0x04, + 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x39, 0x2e, 0x77, 0x6f, 0x72, + 0x6b, 0x66, 0x6c, 0x6f, 0x77, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x2e, 0x76, 0x31, + 0x2e, 0x43, 0x72, 0x61, 0x66, 0x74, 0x69, 0x6e, 0x67, 0x53, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x2e, + 0x4d, 0x61, 0x74, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x2e, 0x4d, 0x61, 0x74, 0x65, 0x72, 0x69, 0x61, + 0x6c, 0x54, 0x79, 0x70, 0x65, 0x42, 0x08, 0xfa, 0x42, 0x05, 0x82, 0x01, 0x02, 0x20, 0x00, 0x52, + 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x24, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x42, 0x10, 0xfa, 0x42, 0x0d, 0x72, 0x0b, 0x32, 0x09, 0x5e, 0x5b, 0x5c, 0x77, + 0x7c, 0x2d, 0x5d, 0x2b, 0x24, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x6f, + 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x6f, + 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x61, 0x6c, 0x12, 0x16, 0x0a, 0x06, 0x6f, 0x75, 0x74, 0x70, 0x75, + 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x12, + 0x41, 0x0a, 0x0b, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x05, + 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x77, 0x6f, 0x72, 0x6b, 0x66, 0x6c, 0x6f, 0x77, 0x63, + 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x2e, 0x76, 0x31, 0x2e, 0x41, 0x6e, 0x6e, 0x6f, 0x74, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0b, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x73, 0x22, 0xbe, 0x01, 0x0a, 0x0c, 0x4d, 0x61, 0x74, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x54, + 0x79, 0x70, 0x65, 0x12, 0x1d, 0x0a, 0x19, 0x4d, 0x41, 0x54, 0x45, 0x52, 0x49, 0x41, 0x4c, 0x5f, + 0x54, 0x59, 0x50, 0x45, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, + 0x10, 0x00, 0x12, 0x0a, 0x0a, 0x06, 0x53, 0x54, 0x52, 0x49, 0x4e, 0x47, 0x10, 0x01, 0x12, 0x13, + 0x0a, 0x0f, 0x43, 0x4f, 0x4e, 0x54, 0x41, 0x49, 0x4e, 0x45, 0x52, 0x5f, 0x49, 0x4d, 0x41, 0x47, + 0x45, 0x10, 0x02, 0x12, 0x0c, 0x0a, 0x08, 0x41, 0x52, 0x54, 0x49, 0x46, 0x41, 0x43, 0x54, 0x10, + 0x03, 0x12, 0x17, 0x0a, 0x13, 0x53, 0x42, 0x4f, 0x4d, 0x5f, 0x43, 0x59, 0x43, 0x4c, 0x4f, 0x4e, + 0x45, 0x44, 0x58, 0x5f, 0x4a, 0x53, 0x4f, 0x4e, 0x10, 0x04, 0x12, 0x12, 0x0a, 0x0e, 0x53, 0x42, + 0x4f, 0x4d, 0x5f, 0x53, 0x50, 0x44, 0x58, 0x5f, 0x4a, 0x53, 0x4f, 0x4e, 0x10, 0x05, 0x12, 0x0d, + 0x0a, 0x09, 0x4a, 0x55, 0x4e, 0x49, 0x54, 0x5f, 0x58, 0x4d, 0x4c, 0x10, 0x06, 0x12, 0x0b, 0x0a, + 0x07, 0x4f, 0x50, 0x45, 0x4e, 0x56, 0x45, 0x58, 0x10, 0x07, 0x12, 0x0c, 0x0a, 0x08, 0x43, 0x53, + 0x41, 0x46, 0x5f, 0x56, 0x45, 0x58, 0x10, 0x08, 0x12, 0x09, 0x0a, 0x05, 0x53, 0x41, 0x52, 0x49, + 0x46, 0x10, 0x09, 0x22, 0x46, 0x0a, 0x0a, 0x41, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x12, 0x22, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, + 0x0e, 0xfa, 0x42, 0x0b, 0x72, 0x09, 0x32, 0x07, 0x5e, 0x5b, 0x5c, 0x77, 0x5d, 0x2b, 0x24, 0x52, + 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x42, 0x4d, 0x5a, 0x4b, 0x67, + 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x6c, + 0x6f, 0x6f, 0x70, 0x2d, 0x64, 0x65, 0x76, 0x2f, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x6c, 0x6f, 0x6f, + 0x70, 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x70, 0x6c, 0x61, + 0x6e, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x77, 0x6f, 0x72, 0x6b, 0x66, 0x6c, 0x6f, 0x77, 0x63, + 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x2f, 0x76, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, } var ( diff --git a/app/controlplane/api/workflowcontract/v1/crafting_schema.proto b/app/controlplane/api/workflowcontract/v1/crafting_schema.proto index f6f2a2ed5..a8c385b35 100644 --- a/app/controlplane/api/workflowcontract/v1/crafting_schema.proto +++ b/app/controlplane/api/workflowcontract/v1/crafting_schema.proto @@ -44,6 +44,7 @@ message CraftingSchema { GITHUB_ACTION = 1; GITLAB_PIPELINE = 2; AZURE_PIPELINE = 3; + JENKINS_JOB = 4; } } From feb0b5fdd9a51378d7e12d8199f9f7c2604e3216 Mon Sep 17 00:00:00 2001 From: Mattia Buccarella Date: Fri, 3 Nov 2023 17:47:01 +0100 Subject: [PATCH 3/4] do not require Git variables Signed-off-by: Mattia Buccarella --- internal/attestation/crafter/runners/jenkinsjob.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/attestation/crafter/runners/jenkinsjob.go b/internal/attestation/crafter/runners/jenkinsjob.go index 410cd5a1f..85c80410a 100644 --- a/internal/attestation/crafter/runners/jenkinsjob.go +++ b/internal/attestation/crafter/runners/jenkinsjob.go @@ -43,8 +43,10 @@ func (r *JenkinsJob) ListEnvVars() []string { "BUILD_URL", // Some info about the commit (Jenkins Git Plugin) - "GIT_BRANCH", - "GIT_COMMIT", + // NOTE: Commenting these vars out because they are not always present + // and current chainloop behavior requires these to be set. + // "GIT_BRANCH", + // "GIT_COMMIT", // Some info about the agent "AGENT_WORKDIR", From ac2e6a569b2201aae72d9d9adf59925487ccb59f Mon Sep 17 00:00:00 2001 From: Mattia Buccarella Date: Fri, 3 Nov 2023 17:57:37 +0100 Subject: [PATCH 4/4] adjusting tests Signed-off-by: Mattia Buccarella --- internal/attestation/crafter/runners/jenkinsjob_test.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/internal/attestation/crafter/runners/jenkinsjob_test.go b/internal/attestation/crafter/runners/jenkinsjob_test.go index c36acc082..37dbf7d67 100644 --- a/internal/attestation/crafter/runners/jenkinsjob_test.go +++ b/internal/attestation/crafter/runners/jenkinsjob_test.go @@ -80,8 +80,6 @@ func (s *jenkinsJobSuite) TestListEnvVars() { s.Equal([]string{ "JOB_NAME", "BUILD_URL", - "GIT_BRANCH", - "GIT_COMMIT", "AGENT_WORKDIR", "NODE_NAME", }, s.runner.ListEnvVars()) @@ -111,8 +109,6 @@ func (s *jenkinsJobSuite) SetupTest() { var jenkinsJobTestingEnvVars = map[string]string{ "JOB_NAME": "some-jenkins-job", "BUILD_URL": "http://some-build-url/", - "GIT_BRANCH": "some-branch", - "GIT_COMMIT": "123", "AGENT_WORKDIR": "/home/sample/agent", "NODE_NAME": "some-node", }