Skip to content

Commit 425445d

Browse files
andrianjardanjloleysenstobio
authored andcommitted
Kibana api key (elastic#372)
* Adding api key functionality for Kibana * Adding support for api_key for Kibana * Adding go-kibana-rest lib locally as it is abandoned by authors * update docs * added support for SLO client to use API keys * add auth interceptor to connectors client * added test case for Kibana API keys via provider * slight fix to table test * added fwschema * fix copy-pasta * some typos, generate docs * manually patch generated code for now * update specs * update new kb config from framework * added api key to provider tests * use built in jq * remove kibana api key env * API keys should cascade from ES->Kibana->Fleet * update rules doc --------- Co-authored-by: Jean-Louis Leysens <[email protected]> Co-authored-by: Toby Brain <[email protected]>
1 parent 91038ab commit 425445d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+3917
-63
lines changed

.github/workflows/test.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,15 @@ jobs:
121121
KIBANA_SYSTEM_USERNAME: ${{ env.KIBANA_SYSTEM_USERNAME }}
122122
KIBANA_SYSTEM_PASSWORD: ${{ env.KIBANA_SYSTEM_PASSWORD }}
123123

124+
- id: get-api-key
125+
name: Get ES API key
126+
run: |-
127+
echo "apikey=$(make create-es-api-key | jq -r .encoded)" >> "$GITHUB_OUTPUT"
128+
env:
129+
ELASTICSEARCH_ENDPOINTS: "http://localhost:9200"
130+
ELASTICSEARCH_USERNAME: "elastic"
131+
ELASTICSEARCH_PASSWORD: ${{ env.ELASTIC_PASSWORD }}
132+
124133
- name: TF acceptance tests
125134
timeout-minutes: 10
126135
run: make testacc
@@ -131,3 +140,4 @@ jobs:
131140
ELASTICSEARCH_USERNAME: "elastic"
132141
ELASTICSEARCH_PASSWORD: ${{ env.ELASTIC_PASSWORD }}
133142
KIBANA_ENDPOINT: "http://localhost:5601"
143+
KIBANA_API_KEY: ${{ steps.get-api-key.outputs.apikey }}

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ KIBANA_NAME ?= terraform-elasticstack-kb
2828
KIBANA_ENDPOINT ?= http://$(KIBANA_NAME):5601
2929
KIBANA_SYSTEM_USERNAME ?= kibana_system
3030
KIBANA_SYSTEM_PASSWORD ?= password
31+
KIBANA_API_KEY_NAME ?= kibana-api-key
3132

3233
SOURCE_LOCATION ?= $(shell pwd)
3334

@@ -129,6 +130,10 @@ docker-network: ## Create a dedicated network for ES and test runs
129130
set-kibana-password: ## Sets the ES KIBANA_SYSTEM_USERNAME's password to KIBANA_SYSTEM_PASSWORD. This expects Elasticsearch to be available at localhost:9200
130131
@ $(call retry, 10, curl -X POST -u $(ELASTICSEARCH_USERNAME):$(ELASTICSEARCH_PASSWORD) -H "Content-Type: application/json" http://localhost:9200/_security/user/$(KIBANA_SYSTEM_USERNAME)/_password -d "{\"password\":\"$(KIBANA_SYSTEM_PASSWORD)\"}" | grep -q "^{}")
131132

133+
.PHONY: create-es-api-key
134+
create-es-api-key: ## Creates and outputs a new API Key. This expects Elasticsearch to be available at localhost:9200
135+
@ $(call retry, 10, curl -X POST -u $(ELASTICSEARCH_USERNAME):$(ELASTICSEARCH_PASSWORD) -H "Content-Type: application/json" http://localhost:9200/_security/api_key -d "{\"name\":\"$(KIBANA_API_KEY_NAME)\"}")
136+
132137
.PHONY: docker-clean
133138
docker-clean: ## Try to remove provisioned nodes and assigned network
134139
@ docker rm -f $(ELASTICSEARCH_NAME) $(KIBANA_NAME) || true

docs/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ Kibana resources will re-use any Elasticsearch credentials specified, these may
9292
- `KIBANA_USERNAME` - The username to use for Kibana authentication
9393
- `KIBANA_PASSWORD` - The password to use for Kibana authentication
9494
- `KIBANA_ENDPOINT` - The Kibana host to connect to
95+
- `KIBANA_API_KEY` - An Elasticsearch API key to use instead of `KIBANA_USERNAME` and `KIBANA_PASSWORD`
9596

9697
Fleet resources will re-use any Kibana or Elasticsearch credentials specified, these may be overridden with the following variables:
9798
- `FLEET_USERNAME` - The username to use for Kibana authentication
@@ -179,6 +180,7 @@ Optional:
179180

180181
Optional:
181182

183+
- `api_key` (String, Sensitive) API Key to use for authentication to Kibana
182184
- `endpoints` (List of String, Sensitive) A comma-separated list of endpoints where the terraform provider will point to, this must include the http(s) schema and port number.
183185
- `insecure` (Boolean) Disable TLS certificate validation
184186
- `password` (String, Sensitive) Password to use for API authentication to Kibana.

docs/resources/kibana_alerting_rule.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ resource "elasticstack_kibana_alerting_rule" "example" {
4040
}
4141
```
4242

43+
44+
**NOTE:** `api_key` authentication is only supported for alerting rule resources from version 8.8.0 of the Elastic stack. Using an `api_key` will result in an error message like:
45+
46+
```
47+
Could not create API key - Unsupported scheme "ApiKey" for granting API Key
48+
```
49+
4350
<!-- schema generated by tfplugindocs -->
4451
## Schema
4552

generated/alerting/api/openapi.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3627,5 +3627,5 @@ components:
36273627
type: http
36283628
apiKeyAuth:
36293629
in: header
3630-
name: ApiKey
3630+
name: Authorization
36313631
type: apiKey

generated/alerting/api_alerting.go

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

generated/alerting/client.go

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

generated/slo/api/openapi.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1550,5 +1550,5 @@ components:
15501550
type: http
15511551
apiKeyAuth:
15521552
in: header
1553-
name: ApiKey
1553+
name: Authorization
15541554
type: apiKey

0 commit comments

Comments
 (0)