-
Notifications
You must be signed in to change notification settings - Fork 109
Kibana api key #372
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
Kibana api key #372
Changes from 3 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
1724ff5
Adding api key functionality for Kibana
andrianjardan 0f738b7
Adding support for api_key for Kibana
andrianjardan 21c74a8
Adding go-kibana-rest lib locally as it is abandoned by authors
andrianjardan bd9d226
Merge branch 'main' into kibana_api_key
andrianjardan c028819
update docs
jloleysens 08611b0
added support for SLO client to use API keys
jloleysens c57830b
add auth interceptor to connectors client
jloleysens e1b5af8
added test case for Kibana API keys via provider
jloleysens 446edfb
slight fix to table test
jloleysens 933da1b
Merge branch 'main' into kibana_api_key
jloleysens dda24a6
added fwschema
jloleysens 39587a8
fix copy-pasta
jloleysens 28a7fd9
some typos, generate docs
jloleysens 3959bac
manually patch generated code for now
jloleysens a95fd7c
update specs
jloleysens ce4c399
update new kb config from framework
jloleysens 068acdd
added api key to provider tests
jloleysens c5123fa
use built in jq
jloleysens 1f0608b
remove kibana api key env
jloleysens bddddbf
API keys should cascade from ES->Kibana->Fleet
tobio e8a3391
Merge branch 'main' into kibana_api_key
jloleysens 0885614
update rules doc
jloleysens 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -247,10 +247,16 @@ func (a *ApiClient) GetFleetClient() (*fleet.Client, error) { | |
} | ||
|
||
func (a *ApiClient) SetAlertingAuthContext(ctx context.Context) context.Context { | ||
return context.WithValue(ctx, alerting.ContextBasicAuth, alerting.BasicAuth{ | ||
UserName: a.kibanaConfig.Username, | ||
Password: a.kibanaConfig.Password, | ||
}) | ||
if a.kibanaConfig.ApiKey != "" { | ||
return context.WithValue(ctx, alerting.ContextAPIKeys, alerting.APIKey{ | ||
Key: a.kibanaConfig.ApiKey, | ||
}) | ||
} else { | ||
return context.WithValue(ctx, alerting.ContextBasicAuth, alerting.BasicAuth{ | ||
UserName: a.kibanaConfig.Username, | ||
Password: a.kibanaConfig.Password, | ||
}) | ||
} | ||
} | ||
|
||
func (a *ApiClient) ID(ctx context.Context, resourceId string) (*CompositeId, diag.Diagnostics) { | ||
|
@@ -508,6 +514,9 @@ func buildKibanaConfig(d *schema.ResourceData, baseConfig BaseConfig) (kibana.Co | |
if password := os.Getenv("KIBANA_PASSWORD"); password != "" { | ||
config.Password = strings.TrimSpace(password) | ||
} | ||
if api_key := os.Getenv("KIBANA_API_KEY"); api_key != "" { | ||
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. Can we make sure this is added to the provider docs as well. |
||
config.ApiKey = strings.TrimSpace(api_key) | ||
} | ||
if endpoint := os.Getenv("KIBANA_ENDPOINT"); endpoint != "" { | ||
config.Address = endpoint | ||
} | ||
|
@@ -524,6 +533,10 @@ func buildKibanaConfig(d *schema.ResourceData, baseConfig BaseConfig) (kibana.Co | |
config.Password = password.(string) | ||
} | ||
|
||
if api_key, ok := kibConfig["api_key"]; ok && api_key != "" { | ||
config.ApiKey = api_key.(string) | ||
} | ||
|
||
if endpoints, ok := kibConfig["endpoints"]; ok && len(endpoints.([]interface{})) > 0 { | ||
// We're curently limited by the API to a single endpoint | ||
if endpoint := endpoints.([]interface{})[0]; endpoint != nil { | ||
|
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: "build" | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- 7.x | ||
- 8.x | ||
tags: | ||
- "*" | ||
pull_request: | ||
branches: | ||
- main | ||
- 7.x | ||
- 8.x | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Setup Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: "1.19" | ||
- name: Setup Elasticsearch / Kibana | ||
run: | | ||
set -e | ||
docker-compose up elasticsearch & | ||
echo "Waiting for Elasticsearch availability" | ||
until curl -s http://localhost:9200 | grep -q 'missing authentication credentials'; do sleep 30; done; | ||
echo "Setting kibana_system password" | ||
until curl -s -X POST -u elastic:changeme -H "Content-Type: application/json" http://localhost:9200/_security/user/kibana_system/_password -d "{\"password\":\"changeme\"}" | grep -q "^{}"; do sleep 10; done | ||
curl -XPOST -u elastic:changeme http://localhost:9200/_license/start_trial?acknowledge=true | ||
docker-compose up kibana & | ||
until $(curl --output /dev/null --silent --head --fail -u elastic:changeme http://localhost:5601); do sleep 5; done | ||
sleep 10 | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v3 | ||
with: | ||
version: latest | ||
args: --timeout 600s | ||
- name: Run build | ||
run: go build | ||
- name: Run test | ||
run: make test | ||
- uses: codecov/codecov-action@v2 | ||
with: | ||
files: coverage.out | ||
flags: unittests | ||
fail_ci_if_error: true |
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,12 @@ | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, build with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out |
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,12 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Debug current file", | ||
"type": "go", | ||
"request": "launch", | ||
"mode": "auto", | ||
"program": "${fileDirname}" | ||
} | ||
] | ||
} |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019 disaster37 | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,18 @@ | ||
TEST?=./... | ||
PKG_NAME=kbapi | ||
KIBANA_URL ?= http://127.0.0.1:5601 | ||
KIBANA_USERNAME ?= elastic | ||
KIBANA_PASSWORD ?= changeme | ||
|
||
all: help | ||
|
||
|
||
test: fmt | ||
KIBANA_URL=${KIBANA_URL} KIBANA_USERNAME=${KIBANA_USERNAME} KIBANA_PASSWORD=${KIBANA_PASSWORD} go test $(TEST) -v -count 1 -parallel 1 -race -coverprofile=coverage.out -covermode=atomic $(TESTARGS) -timeout 120m | ||
|
||
fmt: | ||
@echo "==> Fixing source code with gofmt..." | ||
gofmt -s -w ./ | ||
|
||
|
||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API key support also needs to be added to connectors, as defaults for the fleet client and the SLO auth context
That's too many places :( There must be a better way.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, it would be nice refactor some of this functionality. I'm hopeful we'll have a single client for the entire Kibana surface area soon so that we don't have to implement glue code around all the existing clients.