Skip to content

Commit 99b2307

Browse files
openstack: Fix security group tagging
Before this patch, we used the Neutron call to add tags to the newly created security groups. However, that API doesn't accept tags containing special characters such as slash (`/`), even when url-encoded. With this change, the security groups are tagged with an alternative API call (replace-all-tags) which accepts the tags in a JSON object. Apparently, Neutron accepts special characters (including slash) when they come in a JSON object.
1 parent b2876fc commit 99b2307

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

pkg/infrastructure/openstack/preprovision/securitygroups.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,16 @@ func SecurityGroups(ctx context.Context, installConfig *installconfig.InstallCon
6464
return fmt.Errorf("failed to create the Control plane security group: %w", err)
6565
}
6666

67-
if err := attributestags.Add(ctx, networkClient, "security-groups", masterGroup.ID, "openshiftClusterID="+infraID).ExtractErr(); err != nil {
67+
// The Neutron call to add a tag
68+
// (https://docs.openstack.org/api-ref/network/v2/#add-a-tag)
69+
// doesn't accept all special characters. Here we use the
70+
// "replace-all-tags" call instead, because it accepts a more
71+
// robust JSON body.
72+
//
73+
// see: https://bugzilla.redhat.com/show_bug.cgi?id=2299208
74+
if _, err := attributestags.ReplaceAll(ctx, networkClient, "security-groups", masterGroup.ID, attributestags.ReplaceAllOpts{
75+
Tags: []string{"openshiftClusterID=" + infraID},
76+
}).Extract(); err != nil {
6877
return fmt.Errorf("failed to tag the Control plane security group: %w", err)
6978
}
7079

@@ -76,7 +85,10 @@ func SecurityGroups(ctx context.Context, installConfig *installconfig.InstallCon
7685
return fmt.Errorf("failed to create the Compute security group: %w", err)
7786
}
7887

79-
if err := attributestags.Add(ctx, networkClient, "security-groups", workerGroup.ID, "openshiftClusterID="+infraID).ExtractErr(); err != nil {
88+
// See comment above
89+
if _, err := attributestags.ReplaceAll(ctx, networkClient, "security-groups", workerGroup.ID, attributestags.ReplaceAllOpts{
90+
Tags: []string{"openshiftClusterID=" + infraID},
91+
}).Extract(); err != nil {
8092
return fmt.Errorf("failed to tag the Compute security group: %w", err)
8193
}
8294
}

0 commit comments

Comments
 (0)