-
Couldn't load subscription status.
- Fork 128
New stack provider for environment variables #2298
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
Changes from all commits
Commits
Show all changes
45 commits Select commit Hold shift + click to select a range
b40cd78 Initial code, and removal of reset credentials
jsoriano 47532c3 Assume 410 status gone is ok for elasticsearch
jsoriano b9e112f Refactor client tests so they don't try to use the configured client …
jsoriano a44469d Merge remote-tracking branch 'origin/main' into api-key-support
jsoriano cd980a6 Refactor shellinit
jsoriano 5b41cd9 Use API key in stack clients
jsoriano 12aaebe Ignore errors when getting logs from a non-local elasticsearch
jsoriano cce94bd Share logic to start local services
jsoriano b3b1e76 Fix spaces in logstash config
jsoriano 3797d20 Prepare interfaces to create policies and getting enrollment tokens
jsoriano 04e22d2 Initial enrollment works
jsoriano 8f17940 Tear down
jsoriano 83beb64 Merge remote-tracking branch 'origin/main' into api-key-support
jsoriano 290c6d9 Fix tear down
jsoriano be6dd46 Fix system tests
jsoriano 6169e15 Get kibana host directly from the config?
jsoriano 2e12e02 Fix stack up with logstash
jsoriano f8d1cee Fix logstash with api keys
jsoriano 9a24380 Better idempotence
jsoriano c4822eb Remove unused variable
jsoriano 7295a2e Revert change in initialization of kibana host
jsoriano 0ec34f2 Implement status for environment provider
jsoriano 5f000c5 Try to support local Fleet Server for remote stacks
jsoriano 0a188b4 Merge remote-tracking branch 'origin/main' into api-key-support
jsoriano 184209e Fix certifictes on agent deployer
jsoriano d4d32ac Fix fleet status when fleet server is locally managed
jsoriano 038549c Reuse existing fleet server hosts
jsoriano 91f2b2d Add options for API key in clients
jsoriano b854ca9 Merge remote-tracking branch 'origin/main' into api-key-support
jsoriano 0d1a1b2 Merge branch 'api-key-clients' into api-key-support
jsoriano 74f2049 Add host.docker.internal to the local services
jsoriano bbbc671 Merge remote-tracking branch 'origin/main' into api-key-support
jsoriano 0095a32 Polish status
jsoriano f60e15d Add output id to stack config
jsoriano 0c407a0 Fix error formatting value
jsoriano f53325d Merge remote-tracking branch 'origin/main' into api-key-support
jsoriano dcc5e0b Merge remote-tracking branch 'origin/main' into api-key-support
jsoriano c65452b Merge remote-tracking branch 'origin/main' into api-key-support
jsoriano ffeb24c Remove unused API keys
jsoriano 1079df7 Fix issues after merge
jsoriano 699623e Fix kubernetes agent deployer
jsoriano 699cb0f Add tech preview warning
jsoriano 52ec637 Merge remote-tracking branch 'origin/main' into api-key-support
jsoriano aa71071 Merge remote-tracking branch 'origin/main' into api-key-support
jsoriano d728838 Pass context to call to get enrollment tokens
jsoriano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| | @@ -119,7 +119,7 @@ func (d *DockerComposeAgentDeployer) SetUp(ctx context.Context, agentInfo AgentI | |
| fmt.Sprintf("%s=%s", agentHostnameEnv, d.agentHostname()), | ||
| ) | ||
| | ||
| configDir, err := d.installDockerCompose(agentInfo) | ||
| configDir, err := d.installDockerCompose(ctx, agentInfo) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("could not create resources for custom agent: %w", err) | ||
| } | ||
| | @@ -233,7 +233,7 @@ func (d *DockerComposeAgentDeployer) agentName() string { | |
| | ||
| // installDockerCompose creates the files needed to run the custom elastic agent and returns | ||
| // the directory with these files. | ||
| func (d *DockerComposeAgentDeployer) installDockerCompose(agentInfo AgentInfo) (string, error) { | ||
| func (d *DockerComposeAgentDeployer) installDockerCompose(ctx context.Context, agentInfo AgentInfo) (string, error) { | ||
| customAgentDir, err := CreateDeployerDir(d.profile, fmt.Sprintf("docker-agent-%s-%s", d.agentName(), d.agentRunID)) | ||
| if err != nil { | ||
| return "", fmt.Errorf("failed to create directory for custom agent files: %w", err) | ||
| | @@ -254,14 +254,31 @@ func (d *DockerComposeAgentDeployer) installDockerCompose(agentInfo AgentInfo) ( | |
| if err != nil { | ||
| return "", fmt.Errorf("failed to load config from profile: %w", err) | ||
| } | ||
| enrollmentToken := "" | ||
| if config.ElasticsearchAPIKey != "" { | ||
| // TODO: Review if this is the correct place to get the enrollment token. | ||
| kibanaClient, err := stack.NewKibanaClientFromProfile(d.profile) | ||
| if err != nil { | ||
| return "", fmt.Errorf("failed to create kibana client: %w", err) | ||
| } | ||
| enrollmentToken, err = kibanaClient.GetEnrollmentTokenForPolicyID(ctx, agentInfo.Policy.ID) | ||
| if err != nil { | ||
| return "", fmt.Errorf("failed to get enrollment token for policy %q: %w", agentInfo.Policy.Name, err) | ||
| } | ||
| } | ||
| | ||
| // TODO: Include these settings more explicitly in `config`. | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to have those default values in config directly. In any case, I think this could be changed in a follow-up PR. | ||
| fleetURL := "https://fleet-server:8220" | ||
| kibanaHost := "https://kibana:5601" | ||
| stackVersion := d.stackVersion | ||
| if config.Provider == stack.ProviderServerless { | ||
| fleetURL = config.Parameters[stack.ParamServerlessFleetURL] | ||
| if config.Provider != stack.ProviderCompose { | ||
| kibanaHost = config.KibanaHost | ||
| stackVersion = config.Parameters[stack.ParamServerlessLocalStackVersion] | ||
| } | ||
| if url, ok := config.Parameters[stack.ParamServerlessFleetURL]; ok { | ||
| fleetURL = url | ||
| } | ||
| if version, ok := config.Parameters[stack.ParamServerlessLocalStackVersion]; ok { | ||
| stackVersion = version | ||
| } | ||
mrodm marked this conversation as resolved. Show resolved Hide resolved | ||
| | ||
| agentImage, err := selectElasticAgentImage(stackVersion, agentInfo.Agent.BaseImage) | ||
| | @@ -280,9 +297,10 @@ func (d *DockerComposeAgentDeployer) installDockerCompose(agentInfo AgentInfo) ( | |
| "dockerfile_hash": hex.EncodeToString(hashDockerfile), | ||
| "stack_version": stackVersion, | ||
| "fleet_url": fleetURL, | ||
| "kibana_host": kibanaHost, | ||
| "kibana_host": stack.DockerInternalHost(kibanaHost), | ||
| "elasticsearch_username": config.ElasticsearchUsername, | ||
| "elasticsearch_password": config.ElasticsearchPassword, | ||
| "enrollment_token": enrollmentToken, | ||
| }) | ||
| | ||
| resourceManager.RegisterProvider("file", &resource.FileProvider{ | ||
| | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
116 changes: 116 additions & 0 deletions 116 internal/stack/_static/local-services-docker-compose.yml.tmpl
This file contains hidden or 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,116 @@ | ||
| services: | ||
| {{- $fleet_server_managed := fact "fleet_server_managed" }} | ||
| {{- if eq $fleet_server_managed "true" }} | ||
| {{- $fleet_healthcheck_success_checks := 3 -}} | ||
| {{- $fleet_healthcheck_waiting_time := 1 -}} | ||
| {{- $version := fact "agent_version" -}} | ||
| {{- if semverLessThan $version "8.0.0" -}} | ||
| {{- $fleet_healthcheck_success_checks = 10 -}} | ||
| {{- $fleet_healthcheck_waiting_time = 2 -}} | ||
| {{- end }} | ||
| fleet-server: | ||
| image: "{{ fact "agent_image" }}" | ||
| healthcheck: | ||
| test: "bash /healthcheck.sh {{ $fleet_healthcheck_success_checks }} {{ $fleet_healthcheck_waiting_time }}" | ||
| start_period: 60s | ||
| interval: 5s | ||
| hostname: docker-fleet-server | ||
| environment: | ||
| - "ELASTICSEARCH_HOST={{ fact "elasticsearch_host" }}" | ||
| - "FLEET_SERVER_CERT=/etc/ssl/fleet-server/cert.pem" | ||
| - "FLEET_SERVER_CERT_KEY=/etc/ssl/fleet-server/key.pem" | ||
| - "FLEET_SERVER_ELASTICSEARCH_HOST={{ fact "elasticsearch_host" }}" | ||
| - "FLEET_SERVER_ENABLE=1" | ||
| - "FLEET_SERVER_HOST=0.0.0.0" | ||
| - "FLEET_SERVER_SERVICE_TOKEN={{ fact "fleet_service_token" }}" | ||
| - "FLEET_SERVER_POLICY={{ fact "fleet_server_policy" }}" | ||
| - "FLEET_URL={{ fact "fleet_url" }}" | ||
| - "KIBANA_FLEET_HOST={{ fact "kibana_host" }}" | ||
| - "KIBANA_FLEET_SERVICE_TOKEN={{ fact "fleet_service_token" }}" | ||
| - "KIBANA_FLEET_SERVER_POLICY={{ fact "fleet_server_policy" }}" | ||
| - "KIBANA_FLEET_SETUP=1" | ||
| - "KIBANA_HOST={{ fact "kibana_host" }}" | ||
| volumes: | ||
| - "../certs/ca-cert.pem:/etc/ssl/certs/elastic-package.pem:ro" | ||
| - "../certs/fleet-server:/etc/ssl/fleet-server:ro" | ||
| - "./fleet-server-healthcheck.sh:/healthcheck.sh:ro" | ||
| ports: | ||
| - "127.0.0.1:8220:8220" | ||
| extra_hosts: | ||
| - "host.docker.internal:host-gateway" | ||
| | ||
| fleet-server_is_ready: | ||
| image: tianon/true:multiarch | ||
| depends_on: | ||
| fleet-server: | ||
| condition: service_healthy | ||
| {{- end }} | ||
| | ||
| elastic-agent: | ||
| image: "{{ fact "agent_image" }}" | ||
| {{- if eq $fleet_server_managed "true" }} | ||
| depends_on: | ||
| fleet-server: | ||
| condition: service_healthy | ||
| {{- end }} | ||
| healthcheck: | ||
| test: "elastic-agent status" | ||
| timeout: 2s | ||
| start_period: 360s | ||
| retries: 180 | ||
| interval: 5s | ||
| hostname: docker-fleet-agent | ||
| env_file: "./elastic-agent.env" | ||
| cap_drop: | ||
| - ALL | ||
| volumes: | ||
| - type: bind | ||
| source: ../../../tmp/service_logs/ | ||
| target: /tmp/service_logs/ | ||
| # Mount service_logs under /run too as a testing workaround for the journald input (see elastic-package#1235). | ||
| - type: bind | ||
| source: ../../../tmp/service_logs/ | ||
| target: /run/service_logs/ | ||
| - "../certs/ca-cert.pem:/etc/ssl/certs/elastic-package.pem" | ||
| extra_hosts: | ||
| - "host.docker.internal:host-gateway" | ||
| | ||
| elastic-agent_is_ready: | ||
| image: tianon/true:multiarch | ||
| depends_on: | ||
| elastic-agent: | ||
| condition: service_healthy | ||
| | ||
| {{ $logstash_enabled := fact "logstash_enabled" }} | ||
| {{ if eq $logstash_enabled "true" }} | ||
| logstash: | ||
| build: | ||
| dockerfile: "./Dockerfile.logstash" | ||
| args: | ||
| IMAGE: "{{ fact "logstash_image" }}" | ||
| healthcheck: | ||
| test: bin/logstash -t | ||
| start_period: 120s | ||
| interval: 60s | ||
| timeout: 60s | ||
| retries: 5 | ||
| volumes: | ||
| - "../certs/logstash:/usr/share/logstash/config/certs" | ||
| ports: | ||
| - "127.0.0.1:5044:5044" | ||
| - "127.0.0.1:9600:9600" | ||
| environment: | ||
| - XPACK_MONITORING_ENABLED=false | ||
| - ELASTIC_API_KEY={{ fact "api_key" }} | ||
| - ELASTIC_USER={{ fact "username" }} | ||
| - ELASTIC_PASSWORD={{ fact "password" }} | ||
| - ELASTIC_HOSTS={{ fact "elasticsearch_host" }} | ||
| extra_hosts: | ||
| - "host.docker.internal:host-gateway" | ||
| | ||
| logstash_is_ready: | ||
| image: tianon/true:multiarch | ||
| depends_on: | ||
| logstash: | ||
| condition: service_healthy | ||
| {{ end }} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.