Skip to content

Commit 11b45c5

Browse files
Add basic fips cloudE2E test (#4983)
Verify that FIPS capable artifacts work in cloud deployments. Correct openapi status endpoint return values.
1 parent 49ea898 commit 11b45c5

File tree

11 files changed

+468
-129
lines changed

11 files changed

+468
-129
lines changed

.buildkite/hooks/pre-command

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,19 @@ if [[ "$BUILDKITE_PIPELINE_SLUG" == "fleet-server-package-mbp" ]]; then
4646
fi
4747

4848
if [[ "$BUILDKITE_PIPELINE_SLUG" == "fleet-server" || "$BUILDKITE_PIPELINE_SLUG" == "fleet-server-perf-tests" ]]; then
49-
if [[ "$BUILDKITE_STEP_KEY" == "publish" || "$BUILDKITE_STEP_KEY" == "cloud-e2e-test" || "$BUILDKITE_STEP_KEY" == "create-image" ]]; then
49+
if [[ "$BUILDKITE_STEP_KEY" == "publish" || "$BUILDKITE_STEP_KEY" == "cloud-e2e-test" || "$BUILDKITE_STEP_KEY" == "cloud-e2e-fips-test" || "$BUILDKITE_STEP_KEY" == "create-image" ]]; then
5050
export DOCKER_USERNAME_SECRET=$(retry 5 vault kv get -field user "${DOCKER_REGISTRY_SECRET_PATH}")
5151
export DOCKER_PASSWORD_SECRET=$(retry 5 vault kv get -field password "${DOCKER_REGISTRY_SECRET_PATH}")
5252
docker login -u "${DOCKER_USERNAME_SECRET}" -p "${DOCKER_PASSWORD_SECRET}" "${DOCKER_REGISTRY}" 2>/dev/null
5353
fi
5454
fi
5555

56-
if [[ "$BUILDKITE_PIPELINE_SLUG" == "fleet-server" && "$BUILDKITE_STEP_KEY" == "cloud-e2e-test" ]]; then
57-
export EC_API_KEY_SECRET=$(retry 5 vault kv get -field apiKey "${EC_KEY_SECRET_PATH}")
58-
# Environment variables required by the Elastic Cloud service deployer
59-
export EC_API_KEY=${EC_API_KEY_SECRET}
56+
if [[ "$BUILDKITE_PIPELINE_SLUG" == "fleet-server" ]]; then
57+
if [[ "$BUILDKITE_STEP_KEY" == "cloud-e2e-test" || "$BUILDKITE_STEP_KEY" == "cloud-e2e-fips-test" ]]; then
58+
export EC_API_KEY_SECRET=$(retry 5 vault kv get -field apiKey "${EC_KEY_SECRET_PATH}")
59+
# Environment variables required by the Elastic Cloud service deployer
60+
export EC_API_KEY=${EC_API_KEY_SECRET}
61+
fi
6062
fi
6163

6264
# BK analytics

.buildkite/pipeline.yml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ steps:
4444

4545
- group: "Performance test"
4646
key: "performance-test"
47+
depends_on: "check"
4748
steps:
4849
- label: "Run go benchmark for PR branch"
4950
key: "go-benchmark-pr"
@@ -82,10 +83,9 @@ steps:
8283
agents:
8384
provider: "gcp"
8485

85-
depends_on: "check"
86-
8786
- group: "Run tests"
8887
key: "tests"
88+
depends_on: "check"
8989
steps:
9090
- label: ":smartbear-testexecute: Run unit tests"
9191
key: unit-test
@@ -209,7 +209,28 @@ steps:
209209
allow_failure: false
210210
- step: "e2e-test"
211211
allow_failure: false
212-
depends_on: "check"
212+
213+
- label: ":gcloud: Cloud e2e FIPS Test"
214+
key: "cloud-e2e-fips-test"
215+
env:
216+
DOCKER_REGISTRY: "docker.elastic.co"
217+
DOCKER_BASE_IMAGE: "docker.elastic.co/cloud-release/elastic-agent-fips-cloud"
218+
DOCKER_IMAGE: "docker.elastic.co/beats-ci/elastic-agent-fips-cloud"
219+
DOCKER_IMAGE_TAG: "pr-${BUILDKITE_PULL_REQUEST}-${BUILDKITE_COMMIT:0:12}"
220+
SNAPSHOT: "true"
221+
PLATFORMS: "linux/amd64"
222+
TF_VAR_pull_request: "${BUILDKITE_PULL_REQUEST}"
223+
FIPS: "true"
224+
command: ".buildkite/scripts/cloud_e2e_test.sh"
225+
agents:
226+
provider: "gcp"
227+
depends_on:
228+
- step: "unit-test"
229+
allow_failure: false
230+
- step: "int-test"
231+
allow_failure: false
232+
- step: "e2e-test"
233+
allow_failure: false
213234

214235
- label: ":docker: Publish docker image"
215236
key: "publish"

internal/pkg/api/openapi.gen.go

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/pkg/server/fleet_integration_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ func Test_SmokeTest_CheckinPollTimeout(t *testing.T) {
12331233
AgentId: agentID,
12341234
Message: "test-message",
12351235
Type: api.ACTIONRESULT,
1236-
Subtype: api.ACKNOWLEDGED,
1236+
Subtype: api.EventSubtypeACKNOWLEDGED,
12371237
}
12381238
ev := api.AckRequest_Events_Item{}
12391239
err := ev.FromGenericEvent(event)
@@ -1365,7 +1365,7 @@ func Test_SmokeTest_CheckinPollShutdown(t *testing.T) {
13651365
AgentId: agentID,
13661366
Message: "test-message",
13671367
Type: api.ACTIONRESULT,
1368-
Subtype: api.ACKNOWLEDGED,
1368+
Subtype: api.EventSubtypeACKNOWLEDGED,
13691369
}
13701370
ev := api.AckRequest_Events_Item{}
13711371
err := ev.FromGenericEvent(event)

magefile.go

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@ const (
8282
envDockerImage = "DOCKER_IMAGE"
8383
// envDockerTag is used to indicate tag for images produced by the docker:image target. Defaults to version. It
8484
envDockerTag = "DOCKER_IMAGE_TAG"
85-
// envDockerBaseImage is the image:tag for the base elastic-agent-cloud images used by e2e tests.
85+
// envDockerBaseImage is the base image for elastic-agent-cloud images used by e2e tests.
8686
envDockerBaseImage = "DOCKER_BASE_IMAGE"
87+
// envDockerBaseImageTag is the tag for the base image used by e2e tests.
88+
envDockerBaseImageTag = "DOCKER_BASE_IMAGE_TAG"
8789
)
8890

8991
// const and vars used by magefile.
@@ -997,12 +999,17 @@ func (Docker) Image() error {
997999

9981000
// Push pushs an image created by docker:image to the registry.
9991001
// FIPS may be used to push a FIPS capable image.
1002+
// DOCKER_IMAGE may be used to specify the image name.
10001003
// DOCKER_IMAGE_TAG may be used to specify the image tag.
10011004
func (Docker) Push() error {
10021005
image := dockerImage
10031006
if isFIPS() {
10041007
image += "-fips"
10051008
}
1009+
if v, ok := os.LookupEnv(envDockerImage); ok && v != "" {
1010+
image = v
1011+
}
1012+
10061013
version := getVersion()
10071014
if v, ok := os.LookupEnv(envDockerTag); ok && v != "" {
10081015
version = v
@@ -1015,6 +1022,7 @@ func (Docker) Push() error {
10151022
// This step requires a coverage enabled binary to be used.
10161023
// FIPS is used to control if a FIPS compliant image should be created.
10171024
// DOCKER_BASE_IMAGE may be used to specify the elastic-agent base image. docker.elastic.co/cloud-release/elastic-agent-cloud by default.
1025+
// DOCKER_BASE_IMAGE_TAG may be used to specify the elastic-agent base image tag. Uses the ELASTICESRCH version from dev-tools/integration/.env.
10181026
// DOCKER_IMAGE is used to specify the resulting image name.
10191027
// DOCKER_IMAGE_TAG is used to specify the resulting image tag.
10201028
func (Docker) CustomAgentImage() error {
@@ -1023,16 +1031,21 @@ func (Docker) CustomAgentImage() error {
10231031
return fmt.Errorf("unable to read env file: %w", err)
10241032
}
10251033

1026-
baseImage := "docker.elastic.co/cloud-release/elastic-agent-cloud:" + env["ELASTICSEARCH_VERSION"]
1034+
baseImage := "docker.elastic.co/cloud-release/elastic-agent-cloud"
10271035
if v, ok := os.LookupEnv(envDockerBaseImage); ok && v != "" {
10281036
baseImage = v
10291037
}
1038+
baseImageTag := env["ELASTICSEARCH_VERSION"]
1039+
if v, ok := os.LookupEnv(envDockerBaseImageTag); ok && v != "" {
1040+
baseImageTag = v
1041+
}
1042+
10301043
dockerEnv := map[string]string{"DOCKER_BUILDKIT": "1"}
1031-
err = sh.RunWithV(dockerEnv, "docker", "pull", "--platform", "linux/"+runtime.GOARCH, baseImage)
1044+
err = sh.RunWithV(dockerEnv, "docker", "pull", "--platform", "linux/"+runtime.GOARCH, baseImage+":"+baseImageTag)
10321045
if err != nil {
10331046
return fmt.Errorf("failed to pull image: %w", err)
10341047
}
1035-
vcsRef, err := sh.OutputWith(dockerEnv, "docker", "inspect", "-f", "{{index .Config.Labels \"org.label-schema.vcs-ref\" }}", baseImage)
1048+
vcsRef, err := sh.OutputWith(dockerEnv, "docker", "inspect", "-f", "{{index .Config.Labels \"org.label-schema.vcs-ref\" }}", baseImage+":"+baseImageTag)
10361049
if err != nil {
10371050
return fmt.Errorf("unable to find vcs-ref label: %w", err)
10381051
}
@@ -1050,7 +1063,7 @@ func (Docker) CustomAgentImage() error {
10501063
}
10511064
err = sh.RunWithV(dockerEnv, "docker", "build",
10521065
"-f", filepath.Join("dev-tools", "e2e", "Dockerfile"),
1053-
"--build-arg", "ELASTIC_AGENT_IMAGE="+baseImage,
1066+
"--build-arg", "ELASTIC_AGENT_IMAGE="+baseImage+":"+baseImageTag,
10541067
"--build-arg", "STACK_VERSION="+getVersion(),
10551068
"--build-arg", "VCS_REF_SHORT="+vcsRef[:6],
10561069
"--build-arg", "FLEET_FIPS="+fips,
@@ -2027,6 +2040,7 @@ func (Test) CloudE2E() {
20272040
// DOCKER_IMAGE can be used to specify the custom integration server image.
20282041
// DOCKER_IMAGE_TAG can be used to specify the tag of the custom integration server.
20292042
func (Test) CloudE2EUp() error {
2043+
os.Setenv(envSnapshot, "true")
20302044
imageName := dockerImage
20312045
imageTag := getVersion()
20322046

@@ -2081,16 +2095,35 @@ func (Test) CloudE2EDown() error {
20812095

20822096
// CloudE2ERun runs tests against the remote cloud deployment.
20832097
func (Test) CloudE2ERun() error {
2084-
url, err := sh.Output("terraform", "output", "--raw", "--state="+filepath.Join("dev-tools", "cloud", "terraform", "terraform.tfstate"), "fleet_url")
2098+
fleetURL, err := sh.Output("terraform", "output", "--raw", "--state="+filepath.Join("dev-tools", "cloud", "terraform", "terraform.tfstate"), "fleet_url")
20852099
if err != nil {
20862100
return fmt.Errorf("unable to retrive fleet-server cloud url: %w", err)
20872101
}
20882102

2103+
kibanaURL, err := sh.Output("terraform", "output", "--raw", "--state="+filepath.Join("dev-tools", "cloud", "terraform", "terraform.tfstate"), "kibana_url")
2104+
if err != nil {
2105+
return fmt.Errorf("unable to retrive kibana cloud url: %w", err)
2106+
}
2107+
2108+
user, err := sh.Output("terraform", "output", "--raw", "--state="+filepath.Join("dev-tools", "cloud", "terraform", "terraform.tfstate"), "elasticsearch_username")
2109+
if err != nil {
2110+
return fmt.Errorf("unable to retrive es username: %w", err)
2111+
}
2112+
pass, err := sh.Output("terraform", "output", "--raw", "--state="+filepath.Join("dev-tools", "cloud", "terraform", "terraform.tfstate"), "elasticsearch_password")
2113+
if err != nil {
2114+
return fmt.Errorf("unable to retrive es password: %w", err)
2115+
}
2116+
20892117
var b bytes.Buffer
20902118
w := io.MultiWriter(&b, os.Stdout)
20912119
cmd := exec.Command("go", "test", "-v", "-timeout", "30m", "-tags=cloude2e", "-count=1", "-p", "1", "./...")
20922120
cmd.Dir = "testing"
2093-
cmd.Env = append(os.Environ(), "FLEET_SERVER_URL="+url)
2121+
cmd.Env = append(os.Environ(),
2122+
"FLEET_SERVER_URL="+fleetURL,
2123+
"KIBANA_URL="+kibanaURL,
2124+
"ELASTIC_USER="+user,
2125+
"ELASTIC_PASS="+pass,
2126+
)
20942127
cmd.Stdout = w
20952128
cmd.Stderr = w
20962129
err = cmd.Run()

model/openapi.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,14 @@ components:
8686
A Unit state that fleet-server may report.
8787
Unit state is defined in the elastic-agent-client specification.
8888
enum:
89-
- starting
90-
- configuring
91-
- healthy
92-
- degraded
93-
- failed
94-
- stopping
95-
- stopped
96-
- unknown
89+
- STARTING
90+
- CONFIGURING
91+
- HEALTHY
92+
- DEGRADED
93+
- FAILED
94+
- STOPPING
95+
- STOPPED
96+
- UNKNOWN
9797
version:
9898
$ref: "#/components/schemas/statusResponseVersion"
9999
enrollMetadata:

pkg/api/types.gen.go

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)