-
Notifications
You must be signed in to change notification settings - Fork 83
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
replace secret refs #2863
replace secret refs #2863
Conversation
internal/pkg/dl/secret.go
Outdated
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.
Following the example here: https://github.com/elastic/go-elasticsearch/blob/main/_examples/extension/main.go
internal/pkg/policy/parsed_policy.go
Outdated
return result, nil | ||
} | ||
|
||
func getPolicyInputsWithSecrets(inputsRaw json.RawMessage, secretReferences map[string]string) ([]map[string]interface{}, error) { |
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.
Is it possible to define a type in Go where some fields are known (streams
) and some are dynamic (e.g. package_var_secret
)?
Example inputs and secret refs:
"inputs": [
{
"id": "test_input-secrets-7c6b08d8-dbe5-4278-8929-dfb26ea8e579",
"revision": 1,
"name": "secrets-1",
"type": "test_input",
"data_stream": {
"namespace": "default"
},
"use_output": "default",
"package_policy_id": "7c6b08d8-dbe5-4278-8929-dfb26ea8e579",
"package_var_secret": "$co.elastic.secret{2LnzzokBsuDBJ5hx_Zo_}",
"input_var_secret": "$co.elastic.secret{2bnzzokBsuDBJ5hx_Zo_}",
"streams": [
{
"id": "test_input-secrets.log-7c6b08d8-dbe5-4278-8929-dfb26ea8e579",
"data_stream": {
"type": "logs",
"dataset": "secrets.log"
},
"config.version": "2",
"package_var_secret": "$co.elastic.secret{2LnzzokBsuDBJ5hx_Zo_}",
"input_var_secret": "$co.elastic.secret{2bnzzokBsuDBJ5hx_Zo_}",
"stream_var_secret": "$co.elastic.secret{2rnzzokBsuDBJ5hx_Zo_}"
}
],
"meta": {
"package": {
"name": "secrets",
"version": "1.0.0"
}
}
}
],
"secret_references": [
{
"id": "2LnzzokBsuDBJ5hx_Zo_"
},
{
"id": "2bnzzokBsuDBJ5hx_Zo_"
},
{
"id": "2rnzzokBsuDBJ5hx_Zo_"
}
],
Example of replaced values:
"inputs": [
{
"data_stream": {
"namespace": "default"
},
"id": "test_input-secrets-7c6b08d8-dbe5-4278-8929-dfb26ea8e579",
"input_var_secret": "input",
"meta": {
"package": {
"name": "secrets",
"version": "1.0.0"
}
},
"name": "secrets-1",
"package_policy_id": "7c6b08d8-dbe5-4278-8929-dfb26ea8e579",
"package_var_secret": "pkg",
"revision": 1,
"streams": [
{
"config.version": "2",
"data_stream": {
"dataset": "secrets.log",
"type": "logs"
},
"id": "test_input-secrets.log-7c6b08d8-dbe5-4278-8929-dfb26ea8e579",
"input_var_secret": "input",
"package_var_secret": "pkg",
"stream_var_secret": "stream"
}
],
"type": "test_input",
"use_output": "default"
}
]
I'm planning to add an integration or e2e test for this, though not sure how to create a secret as it requires privileges that only |
if len(policies) == 0 { | ||
return nil | ||
} | ||
|
||
latest := m.groupByLatest(policies) | ||
for _, policy := range latest { | ||
pp, err := NewParsedPolicy(policy) | ||
pp, err := NewParsedPolicy(ctx, m.bulker, policy) |
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.
Ah we get policies through the monitor - so I think this will be shared with all agents current subscribed to checkin. That should minimize the amount of re-fetching we have to do here.
Co-authored-by: Josh Dover <[email protected]>
Co-authored-by: Josh Dover <[email protected]>
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.
LGTM thanks for the e2e test!
I'm seeing some flakyness with integration tests using fake checkin request:
|
The integration tests all pass now, but there is still an issue that I don't know how to fix:
Line 328 is this: Line 328 in 4834215
Trying to revert the last 3 commits as I saw a passing built at that point. |
49595c5
to
918592a
Compare
Did the last commit fix? Seems like it should. Otherwise I can dig in to help |
I had a passing build before this commit, which excludes some unit tests from the integration tests run, not sure if this is flakyness, or something breaks when I exclude those. I think I got it, it seems that an integration test referenced a variable from a unit test and it was missing when I excluded the unit test.
|
fa41fef
to
ca9ec09
Compare
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
//go:build !integration |
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 don't understand though we we have to exclude unit tests like this explicitly, as integration tests are tagged also.
Are we missing something?
the Makefile has this command to tigger integration tests:
go test -v -tags=integration -count=1 -race -p 1 ./...
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 guess that the idea is to don't run unit tests when running integration tests, so the same tests are not executed at two different stages of testing.
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.
Yes, I mean shouldn't it be enough to mark integration tests with //go:build integration
? I think it's easy to forget when adding new unit tests to add the negated condition, and I'm trying to understand why it is needed.
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.
Files without any build tag are always included, so -tags=integration
wouldn't discard unit test files if they don't have the negated tag. So we need !integration
for test files that we don't want to execute during integration tests.
I agree that this is easy to forget. Tough I wouldn't see as a great problem to execute some fast unit tests during integration test execution.
If we strongly want to have their execution separated, a possible strategy to don't forget it is to have only unit tests in packages, and move the integration tests to their own package/s, in a similar fashion to what we do for e2e tests. This also help to validate interfaces.
Or we could have some check in CI to ensure that all test files have tags.
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.
Thanks for the explanation!
What is the problem this PR solves?
Agent policy secrets are sent to agents in agent policy.
How does this PR solve the problem?
On checkin, read secret values of secret references in the agent policy, and replace occurrences in input and stream variables.
How to test this PR locally
kibana.dev.yml
:xpack.fleet.enableExperimental: ['secretsStorage']
computed-config.yml
that the inputs contain the secret values, not referencesinput not supported
is not related to secrets, looks like a validation changed on agent side, so that the test package doesn't have a valid input type. Can be ignored for now.Example:
Design Checklist
Checklist
./changelog/fragments
using the changelog toolRelated issues
.fleet-secrets
index and replace secret references with secret values #2485