Skip to content

Commit

Permalink
[Fleet] Fix security solution tag id (elastic#164582)
Browse files Browse the repository at this point in the history
Related to elastic#152814

## Summary

Fix for a bug found in elastic#162643 :
The security solution tag is actually created with "Security Solution"
name and "security-solution-default" id (instead of `SecuritySolution`):

```
   {
        "id": "security-solution-default",
        "name": "Security Solution",
        "description": "",
        "color": "#D36086"
    }
```

I found that in same cases the tag is duplicated, since[ is not created
with an unique
id](https://github.com/elastic/kibana/blob/dd0938bea3ebd745a49ac164a7a5f053ba6a138b/x-pack/plugins/security_solution/public/dashboards/containers/use_fetch_security_tags.ts#L44-L51):

<img width="3079" alt="Screenshot 2023-08-23 at 15 07 09"
src="https://github.com/elastic/kibana/assets/16084106/ef885d8f-2e68-4695-aa14-1adc2e326ab0">

I think it's acceptable to use the "security-solution-default", at least
it will create the correct tag name.

### Test
For testing I used a package built locally that uses the `Security
Solution` tag
The steps are the same as described in
elastic#162643

- Additionally, check that the `tags` endpoint in the Tags page has name
and id as described above:
<img width="2521" alt="Screenshot 2023-08-23 at 14 55 05"
src="https://github.com/elastic/kibana/assets/16084106/48b3ddd0-3d04-4ff6-8a24-946902687b13">
  • Loading branch information
criamico authored Aug 24, 2023
1 parent 59f2058 commit da8d3b2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ describe('tagKibanaAssets', () => {
} as any;
const assetTags = [
{
text: 'SecuritySolution',
text: 'Security Solution',
asset_types: ['dashboard'],
},
];
Expand Down Expand Up @@ -733,9 +733,9 @@ describe('tagKibanaAssets', () => {
{
color: expect.any(String),
description: 'Tag defined in package-spec',
name: 'SecuritySolution',
name: 'Security Solution',
},
{ id: 'SecuritySolution', overwrite: true, refresh: false }
{ id: 'security-solution-default', overwrite: true, refresh: false }
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ const MANAGED_TAG_COLOR = '#0077CC';
const PACKAGE_TAG_COLOR = '#4DD2CA';
const MANAGED_TAG_NAME = 'Managed';
const LEGACY_MANAGED_TAG_ID = 'managed';
const SECURITY_SOLUTION_TAG_ID = 'SecuritySolution';
const SECURITY_SOLUTION_TAG_NAME = 'Security Solution';
const SECURITY_SOLUTION_TAG_ID = 'security-solution-default';

// the tag service only accepts 6-digits hex colors
const TAG_COLORS = [
Expand All @@ -61,10 +62,10 @@ const getLegacyPackageTagId = (pkgName: string) => pkgName;
/*
This function is exported via fleet/plugin.ts to make it available to other plugins
The `SecuritySolution` tag is a special case that needs to be handled separately
In that case simply return `SecuritySolution`
In that case return id `security-solution-default`
*/
export const getPackageSpecTagId = (spaceId: string, pkgName: string, tagName: string) => {
if (tagName.toLowerCase() === SECURITY_SOLUTION_TAG_ID.toLowerCase())
if (tagName.toLowerCase() === SECURITY_SOLUTION_TAG_NAME.toLowerCase())
return SECURITY_SOLUTION_TAG_ID;
// UUID v5 needs a namespace (uuid.DNS) to generate a predictable uuid
const uniqueId = uuidv5(`${tagName.toLowerCase()}`, uuidv5.DNS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export default function (providerContext: FtrProviderContext) {

describe('Handles presence of tags inside integration package', async () => {
const testPackage = 'assets_with_tags';
const testPackageVersion = '0.1.0';
const testPackageVersion = '0.1.1';
// tag corresponding to `OnlySomeAssets`
const ONLY_SOME_ASSETS_TAG = `fleet-shared-tag-${testPackage}-ef823f10-b5af-5fcb-95da-2340a5257599-default`;
// tag corresponding to `MixedTypesTag`
Expand All @@ -167,7 +167,7 @@ export default function (providerContext: FtrProviderContext) {

const testPkgArchiveZip = path.join(
path.dirname(__filename),
'../fixtures/direct_upload_packages/assets_with_tags-0.1.0.zip'
'../fixtures/direct_upload_packages/assets_with_tags-0.1.1.zip'
);
const buf = fs.readFileSync(testPkgArchiveZip);
await supertest
Expand All @@ -187,7 +187,7 @@ export default function (providerContext: FtrProviderContext) {
const managedTag = await getTag('fleet-managed-default');
expect(managedTag).not.equal(undefined);

const securitySolutionTag = await getTag('SecuritySolution');
const securitySolutionTag = await getTag('security-solution-default');
expect(securitySolutionTag).not.equal(undefined);

const pkgTag1 = await getTag(ONLY_SOME_ASSETS_TAG);
Expand Down
Binary file not shown.

0 comments on commit da8d3b2

Please sign in to comment.