Skip to content

Commit 96a465d

Browse files
committed
OCPBUGS-44199: Allow spaces in AWS resource tags
An incorrect regex validation prevents users from specifying AWS tag keys or values that include spaces, which are allowed by AWS's official regex: https://docs.aws.amazon.com/directoryservice/latest/devguide/API_Tag.html Also includes some API cleanup.
1 parent afdfbaf commit 96a465d

File tree

2 files changed

+170
-4
lines changed

2 files changed

+170
-4
lines changed

config/v1/tests/infrastructures.config.openshift.io/AAA_ungated.yaml

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
apiVersion: apiextensions.k8s.io/v1 # Hack because controller-gen complains if we don't have this
22
name: "Infrastructure"
33
crdName: infrastructures.config.openshift.io
4+
featureGates:
5+
- -AWSClusterHostedDNS
46
tests:
57
onCreate:
68
- name: Should be able to create a minimal Infrastructure
@@ -1675,3 +1677,163 @@ tests:
16751677
serviceEndpoints:
16761678
- name: DNSServices
16771679
url: https://abc
1680+
- name: Should be able to create an aws resourcetag with spaces
1681+
initial: |
1682+
apiVersion: config.openshift.io/v1
1683+
kind: Infrastructure
1684+
spec:
1685+
platformSpec:
1686+
aws: {}
1687+
type: AWS
1688+
status:
1689+
controlPlaneTopology: HighlyAvailable
1690+
cpuPartitioning: None
1691+
infrastructureTopology: HighlyAvailable
1692+
platform: AWS
1693+
platformStatus:
1694+
aws:
1695+
region: us-east-1
1696+
resourceTags:
1697+
- key: key with space
1698+
value: value with space
1699+
type: AWS
1700+
updated: |
1701+
apiVersion: config.openshift.io/v1
1702+
kind: Infrastructure
1703+
spec:
1704+
platformSpec:
1705+
type: AWS
1706+
aws: {}
1707+
status:
1708+
controlPlaneTopology: HighlyAvailable
1709+
cpuPartitioning: None
1710+
infrastructureTopology: HighlyAvailable
1711+
platform: AWS
1712+
platformStatus:
1713+
aws:
1714+
region: us-east-1
1715+
resourceTags:
1716+
- key: key with space
1717+
value: value with space
1718+
type: AWS
1719+
expected: |
1720+
apiVersion: config.openshift.io/v1
1721+
kind: Infrastructure
1722+
spec:
1723+
platformSpec:
1724+
type: AWS
1725+
aws: {}
1726+
status:
1727+
controlPlaneTopology: HighlyAvailable
1728+
cpuPartitioning: None
1729+
infrastructureTopology: HighlyAvailable
1730+
platform: AWS
1731+
platformStatus:
1732+
aws:
1733+
region: us-east-1
1734+
resourceTags:
1735+
- key: key with space
1736+
value: value with space
1737+
type: AWS
1738+
- name: Should be able to create an aws resourcetag with characters '_', '.', '/', '=', '+', '-', ':', '@'
1739+
initial: |
1740+
apiVersion: config.openshift.io/v1
1741+
kind: Infrastructure
1742+
spec:
1743+
platformSpec:
1744+
aws: {}
1745+
type: AWS
1746+
updated: |
1747+
apiVersion: config.openshift.io/v1
1748+
kind: Infrastructure
1749+
spec:
1750+
platformSpec:
1751+
type: AWS
1752+
aws: {}
1753+
status:
1754+
controlPlaneTopology: HighlyAvailable
1755+
cpuPartitioning: None
1756+
infrastructureTopology: HighlyAvailable
1757+
platform: AWS
1758+
platformStatus:
1759+
aws:
1760+
region: us-east-1
1761+
resourceTags:
1762+
- key: key:_./=+-@
1763+
value: value:_./=+-@
1764+
type: AWS
1765+
expected: |
1766+
apiVersion: config.openshift.io/v1
1767+
kind: Infrastructure
1768+
spec:
1769+
platformSpec:
1770+
type: AWS
1771+
aws: {}
1772+
status:
1773+
controlPlaneTopology: HighlyAvailable
1774+
cpuPartitioning: None
1775+
infrastructureTopology: HighlyAvailable
1776+
platform: AWS
1777+
platformStatus:
1778+
aws:
1779+
region: us-east-1
1780+
resourceTags:
1781+
- key: key:_./=+-@
1782+
value: value:_./=+-@
1783+
type: AWS
1784+
- name: Should not be able to create an aws resourcetag with character * in key
1785+
initial: |
1786+
apiVersion: config.openshift.io/v1
1787+
kind: Infrastructure
1788+
spec:
1789+
platformSpec:
1790+
aws: {}
1791+
type: AWS
1792+
updated: |
1793+
apiVersion: config.openshift.io/v1
1794+
kind: Infrastructure
1795+
spec:
1796+
platformSpec:
1797+
type: AWS
1798+
aws: {}
1799+
status:
1800+
controlPlaneTopology: HighlyAvailable
1801+
cpuPartitioning: None
1802+
infrastructureTopology: HighlyAvailable
1803+
platform: AWS
1804+
platformStatus:
1805+
aws:
1806+
region: us-east-1
1807+
resourceTags:
1808+
- key: key:_./=+-@*
1809+
value: value
1810+
type: AWS
1811+
expectedStatusError: "invalid AWS resource tag key. The string can contain only the set of alphanumeric characters, space (' '), '_', '.', '/', '=', '+', '-', ':', '@'"
1812+
- name: Should not be able to create an aws resourcetag with character * in value
1813+
initial: |
1814+
apiVersion: config.openshift.io/v1
1815+
kind: Infrastructure
1816+
spec:
1817+
platformSpec:
1818+
aws: {}
1819+
type: AWS
1820+
updated: |
1821+
apiVersion: config.openshift.io/v1
1822+
kind: Infrastructure
1823+
spec:
1824+
platformSpec:
1825+
type: AWS
1826+
aws: {}
1827+
status:
1828+
controlPlaneTopology: HighlyAvailable
1829+
cpuPartitioning: None
1830+
infrastructureTopology: HighlyAvailable
1831+
platform: AWS
1832+
platformStatus:
1833+
aws:
1834+
region: us-east-1
1835+
resourceTags:
1836+
- key: key
1837+
value: value*
1838+
type: AWS
1839+
expectedStatusError: "invalid AWS resource tag value. The string can contain only the set of alphanumeric characters, space (' '), '_', '.', '/', '=', '+', '-', ':', '@'"

config/v1/types_infrastructure.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -528,18 +528,22 @@ type AWSPlatformStatus struct {
528528

529529
// AWSResourceTag is a tag to apply to AWS resources created for the cluster.
530530
type AWSResourceTag struct {
531-
// key is the key of the tag
531+
// key sets the key of the AWS resource tag key-value pair. Key is required when defining an AWS resource tag.
532+
// Key should consist of between 1 and 128 characters, and may
533+
// contain only the set of alphanumeric characters, space (' '), '_', '.', '/', '=', '+', '-', ':', and '@'.
532534
// +kubebuilder:validation:MinLength=1
533535
// +kubebuilder:validation:MaxLength=128
534-
// +kubebuilder:validation:Pattern=`^[0-9A-Za-z_.:/=+-@]+$`
536+
// +kubebuilder:validation:XValidation:rule=`self.matches('^[0-9A-Za-z_.:/=+-@ ]+$')`,message="invalid AWS resource tag key. The string can contain only the set of alphanumeric characters, space (' '), '_', '.', '/', '=', '+', '-', ':', '@'"
535537
// +required
536538
Key string `json:"key"`
537-
// value is the value of the tag.
539+
// value sets the value of the AWS resource tag key-value pair. Value is required when defining an AWS resource tag.
540+
// Value should consist of between 1 and 256 characters, and may
541+
// contain only the set of alphanumeric characters, space (' '), '_', '.', '/', '=', '+', '-', ':', and '@'.
538542
// Some AWS service do not support empty values. Since tags are added to resources in many services, the
539543
// length of the tag value must meet the requirements of all services.
540544
// +kubebuilder:validation:MinLength=1
541545
// +kubebuilder:validation:MaxLength=256
542-
// +kubebuilder:validation:Pattern=`^[0-9A-Za-z_.:/=+-@]+$`
546+
// +kubebuilder:validation:XValidation:rule=`self.matches('^[0-9A-Za-z_.:/=+-@ ]+$')`,message="invalid AWS resource tag value. The string can contain only the set of alphanumeric characters, space (' '), '_', '.', '/', '=', '+', '-', ':', '@'"
543547
// +required
544548
Value string `json:"value"`
545549
}

0 commit comments

Comments
 (0)