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

Add tags to fleet server #1350

Merged
merged 8 commits into from
May 9, 2022
Merged

Add tags to fleet server #1350

merged 8 commits into from
May 9, 2022

Conversation

narph
Copy link
Contributor

@narph narph commented Apr 14, 2022

What is the problem this PR solves?

Issue elastic/elastic-agent#149

Add ability to set tags during installation and enrolment agent
so that different identical deployments of service can be differentiated in the dataset

The specific use case is described in: https://discuss.elastic.co/t/fleet-managed-elastic-agent-environment-deployment-name-custom-field/282565/6

sudo ./elastic-agent install -f --url=https://<feet manager>:443 --enrollment-token=<token> --tag=staging01 linux
or in case, the agent is already installed via package manager

elastic-agent enroll -f --url=https://<feet manager>:443 --enrollment-token=<token> --tag=staging01 linux

Checklist

  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

Desired behavior:

 .\elastic-agent.exe enroll  --url=https://192.0.2.1:8220 --fleet-server-es=http://localhost:9200  --fleet-server-service-token=AAEAAWVsYXN0aWMvZmxlZXQtc2VydmVyL3Rva2VuLTE2NTA5NTg3Mjc0OTU6TmVHbEx4WWtUaVNETHNmNmNPV09lZw  --fleet-server-policy=fleet-server-policy --insecure --tag this-is-fleet,windows
{
        "_index": ".fleet-agents-7",
        "_id": "d1c66b32-72ed-4ab3-a36c-9660a5cb7125",
        "_score": null,
        "_source": {
          "access_api_key_id": "TW7SZIAB2-L_WJKcJz9m",
          "action_seq_no": [
            -1
          ],
          "active": true,
          "agent": {
            "id": "d1c66b32-72ed-4ab3-a36c-9660a5cb7125",
            "version": "8.3.0"
          },
          "enrolled_at": "2022-04-26T07:42:15Z",
          "local_metadata": {
            "elastic": {
              "agent": {
                "build.original": "8.3.0-SNAPSHOT (build: 2312423496161dd6f05148d2df0941d2c74570c8 at 2022-04-25 13:23:01 +0000 UTC)",
                "id": "d1c66b32-72ed-4ab3-a36c-9660a5cb7125",
                "log_level": "info",
                "snapshot": true,
                "upgradeable": true,
                "version": "8.3.0"
              }
            },
            "host": {
              "architecture": "x86_64",
              "hostname": "DESKTOP-K76UDQL",
              "id": "bc395ab9-1a1a-4312-ad0b-a05cceaf78f1",
              "ip": [
                "fe80::1d58:b17:4161:9414/64",
                "169.254.148.20/16",
                "2a02:a446:f25b:1:558d:72b2:74b6:7c67/64",
                "fe80::558d:72b2:74b6:7c67/64",
                "192.168.2.26/24",
                "fe80::d135:57b1:9b7f:e10a/64",
                "169.254.225.10/16",
                "fe80::6901:1ee0:60dd:c986/64",
                "169.254.201.134/16",
                "fe80::f09a:4481:bc48:e3e3/64",
                "192.168.21.110/24",
                "fe80::fc98:6ed8:6d25:3d98/64",
                "169.254.61.152/16",
                "::1/128",
                "127.0.0.1/8",
                "fe80::b54c:5acc:d25c:75e9/64",
                "172.23.192.1/20",
                "fe80::3186:c6c:cd37:92b8/64",
                "172.18.224.1/20"
              ],
              "mac": [
                "00:ff:6d:ef:82:d6",
                "cc:48:3a:b9:87:c0",
                "9e:b6:d0:3e:a8:c4",
                "ae:b6:d0:3e:a8:c4",
                "9c:b6:d0:3e:a8:c4",
                "28:c2:1f:52:ff:bf",
                "00:15:5d:a0:47:13",
                "00:15:5d:ff:9c:07"
              ],
              "name": "DESKTOP-K76UDQL"
            },
            "os": {
              "family": "windows",
              "full": "Windows 10 Pro(10.0)",
              "kernel": "10.0.22000.613 (WinBuild.160101.0800)",
              "name": "Windows 10 Pro",
              "platform": "windows",
              "version": "10.0"
            }
          },
          "policy_id": "fleet-server-policy",
          "tags": [
            "this-is-fleet",
            "windows"
          ],
          "type": "PERMANENT"
        },
        "sort": [
          1650958935000
        ]
      }
./elastic-agent.exe container -h

....
The following environment variables are provided as a convenience to prevent a large number of environment variable to
be used when the same credentials will be used across all the possible actions above.

  ELASTICSEARCH_HOST - elasticsearch host [http://elasticsearch:9200]
  ELASTICSEARCH_USERNAME - elasticsearch username [elastic]
  ELASTICSEARCH_PASSWORD - elasticsearch password [changeme]
  ELASTICSEARCH_CA - path to certificate authority to use with communicate with elasticsearch
  KIBANA_HOST - kibana host [http://kibana:5601]
  KIBANA_FLEET_USERNAME - kibana username to enable Fleet [$ELASTICSEARCH_USERNAME]
  KIBANA_FLEET_PASSWORD - kibana password to enable Fleet [$ELASTICSEARCH_PASSWORD]
  KIBANA_CA - path to certificate authority to use with communicate with Kibana [$ELASTICSEARCH_CA]
  ELASTIC_AGENT_TAGS - user provided tags for the agent
....

@mergify
Copy link
Contributor

mergify bot commented Apr 14, 2022

This pull request is now in conflicts. Could you fix it @narph? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b add-tags upstream/add-tags
git merge upstream/main
git push upstream add-tags

@mergify
Copy link
Contributor

mergify bot commented Apr 14, 2022

This pull request does not have a backport label. Could you fix it @narph? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-v/d./d./d is the label to automatically backport to the 7./d branch. /d is the digit

NOTE: backport-skip has been added to this pull request.

@mergify mergify bot added the backport-skip Skip notification from the automated backport with mergify label Apr 14, 2022
@narph narph self-assigned this Apr 14, 2022
@narph narph added 8.3-candidate Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team labels Apr 14, 2022
@elasticmachine
Copy link
Contributor

elasticmachine commented Apr 14, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-04-29T12:24:23.632+0000

  • Duration: 10 min 22 sec

Test stats 🧪

Test Results
Failed 0
Passed 274
Skipped 1
Total 275

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

CHANGELOG.next.asciidoc Outdated Show resolved Hide resolved
@ph
Copy link
Contributor

ph commented Apr 27, 2022

@narph I would really like to see a test for enrollment, Looking at the code it seems we don't have anything already in place, so it's a bit painful. Can you take a look?

Co-authored-by: Pier-Hugues Pellerin <phpellerin@gmail.com>
@narph narph requested a review from ph May 3, 2022 08:31
Copy link
Contributor

@ph ph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@narph narph merged commit dd0d8f5 into elastic:main May 9, 2022
@narph narph deleted the add-tags branch May 9, 2022 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-skip Skip notification from the automated backport with mergify Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team v8.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants