Skip to content
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

[Fleet] Upgrade APIs to support moving a value from .fleet-policies to secrets index when a field moves to being secret #162045

Closed
juliaElastic opened this issue Jul 17, 2023 · 5 comments · Fixed by #164583
Assignees
Labels
Team:Fleet Team label for Observability Data Collection Fleet team

Comments

@juliaElastic
Copy link
Contributor

juliaElastic commented Jul 17, 2023

Part of #154715

Scenario not implemented yet:

  • Fleet has an agent policy with an integration
  • Change a field in the integration to become secret in a new version (supposing feature flag is enabled)
  • Upgrade the integration to use the new version
  • Expect that the secret field is moved from being stored in the policy to the secrets index.
@juliaElastic juliaElastic added the Team:Fleet Team label for Observability Data Collection Fleet team label Jul 17, 2023
@elasticmachine
Copy link
Contributor

Pinging @elastic/fleet (Team:Fleet)

@juliaElastic juliaElastic changed the title [Fleet] Upgrade APIs to support moving a value from .fleet-policies to secrets index when a field moves to being secret [Fleet] Upgrade APIs to support moving a value from .fleet-policies to secrets index when a field moves to being secret Jul 17, 2023
@juliaElastic
Copy link
Contributor Author

juliaElastic commented Aug 14, 2023

I did a test of this by installing latest system package (1.38.2) and then uploading a newer version where made 2 existing vars secret: ignore_older in syslog datastream vars, and url in package vars in version 1.38.3.

Uploaded the package like this:
curl -XPOST -H 'content-type: application/zip' -H 'kbn-xsrf: true' http://localhost:5601/julia/api/fleet/epm/packages -u elastic:changeme --data-binary @system-1.38.3.zip

system-1.38.3.zip

And then upgraded the package and integration policy from the UI.

Verified that the secret vars became secret refs, and the agent got the secret values.

GET .kibana_ingest/_search?q=ingest-package-policies.package.name:system

      "vars": {
                      "ignore_older": {
                        "type": "text",
                        "value": {
                          "isSecretRef": true,
                          "id": "6LN09IkB4EEjyKF9cMBH"
                        }
                      },

  "url": {
                    "type": "text",
                    "value": {
                      "isSecretRef": true,
                      "id": "6bN09IkB4EEjyKF9cMBH"
                    }
                  },

So I think the main functionality works as expected.

One thing I'm not sure is a bug or expected, is that when I look at the agent policy with View policy, I see the request.url with the secret envvar, having a path after it:

image

When I look at the same config in agent computed-config.yaml, I only see request.url: https://server.example.com:8090 that is coming from the secret value. So I'm not sure if the path /services/search/jobs/export should be there or not.

EDIT: checked the same variables without secrets (system-1.38.2) and the agent gets the full url, so I think this is a bug in fleet-server logic that replaces the variables:
should be: request.url: https://server.example.com:8089/services/search/jobs/export

EDIT: Raised a pr to do some cleanup elastic/fleet-server#2876 and can't reproduce the request.url issue anymore locally, the computed config contains the path after the secret value as expected.
request.url: https://server.example.com:8090/services/search/jobs/export

@joshdover
Copy link
Contributor

@juliaElastic Doesn't this show that the upgrade scenario in this issue is already working?

I think we should have explicit API functional tests for this in any case.

@juliaElastic
Copy link
Contributor Author

@joshdover Yes, I think this is working.
Hey @jillguyonnet, you could add some API integration tests for this scenario in this issue, as it looks like the implementation is already done.

@jlind23
Copy link
Contributor

jlind23 commented Aug 22, 2023

@jillguyonnet can you add your integration tests PR here as soon as ready? Thanks

jillguyonnet added a commit that referenced this issue Aug 24, 2023
## Summary

Closes #162045

This PR adds an API integration test for the following scenario:
- Given an integration with some non secret (plain text) vars that
become secret in a newer version;
- When Fleet has an agent policy with this integration and upgrades from
the old to the newer version;
- Then the vars that have become secrets should correctly be stored as
secret values.

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: Julia Bardi <[email protected]>
kibanamachine pushed a commit to kibanamachine/kibana that referenced this issue Aug 24, 2023
## Summary

Closes elastic#162045

This PR adds an API integration test for the following scenario:
- Given an integration with some non secret (plain text) vars that
become secret in a newer version;
- When Fleet has an agent policy with this integration and upgrades from
the old to the newer version;
- Then the vars that have become secrets should correctly be stored as
secret values.

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: Julia Bardi <[email protected]>
(cherry picked from commit 766ff8f)
kibanamachine referenced this issue Aug 24, 2023
…64666)

# Backport

This will backport the following commits from `main` to `8.10`:
- [[Fleet] Add secrets package API integration test
(#164583)](#164583)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Jill
Guyonnet","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-08-24T07:37:34Z","message":"[Fleet]
Add secrets package API integration test (#164583)\n\n##
Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/162045\r\n\r\nThis PR adds an
API integration test for the following scenario:\r\n- Given an
integration with some non secret (plain text) vars that\r\nbecome secret
in a newer version;\r\n- When Fleet has an agent policy with this
integration and upgrades from\r\nthe old to the newer version;\r\n- Then
the vars that have become secrets should correctly be stored
as\r\nsecret values.\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Julia Bardi
<[email protected]>","sha":"766ff8fa614d6b62b750c0eef9c1d129b2187e4f","branchLabelMapping":{"^v8.11.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Fleet","v8.10.0","v8.11.0"],"number":164583,"url":"https://github.com/elastic/kibana/pull/164583","mergeCommit":{"message":"[Fleet]
Add secrets package API integration test (#164583)\n\n##
Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/162045\r\n\r\nThis PR adds an
API integration test for the following scenario:\r\n- Given an
integration with some non secret (plain text) vars that\r\nbecome secret
in a newer version;\r\n- When Fleet has an agent policy with this
integration and upgrades from\r\nthe old to the newer version;\r\n- Then
the vars that have become secrets should correctly be stored
as\r\nsecret values.\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Julia Bardi
<[email protected]>","sha":"766ff8fa614d6b62b750c0eef9c1d129b2187e4f"}},"sourceBranch":"main","suggestedTargetBranches":["8.10"],"targetPullRequestStates":[{"branch":"8.10","label":"v8.10.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.11.0","labelRegex":"^v8.11.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/164583","number":164583,"mergeCommit":{"message":"[Fleet]
Add secrets package API integration test (#164583)\n\n##
Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/162045\r\n\r\nThis PR adds an
API integration test for the following scenario:\r\n- Given an
integration with some non secret (plain text) vars that\r\nbecome secret
in a newer version;\r\n- When Fleet has an agent policy with this
integration and upgrades from\r\nthe old to the newer version;\r\n- Then
the vars that have become secrets should correctly be stored
as\r\nsecret values.\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Julia Bardi
<[email protected]>","sha":"766ff8fa614d6b62b750c0eef9c1d129b2187e4f"}}]}]
BACKPORT-->

Co-authored-by: Jill Guyonnet <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team:Fleet Team label for Observability Data Collection Fleet team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants