Skip to content

Commit

Permalink
Merge pull request #12999 from torchiaf/12679-ca-bundle-2.10
Browse files Browse the repository at this point in the history
[2.10.2] Support caBundle plain text
  • Loading branch information
torchiaf authored Jan 8, 2025
2 parents 35cbf5b + 2d882d7 commit a2bf86d
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 12 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
"intl-messageformat": "7.8.4",
"ip": "2.0.1",
"ipaddr.js": "2.2.0",
"is-base64": "1.1.0",
"is-url": "1.2.4",
"jexl": "2.2.2",
"jquery": "3.5.1",
Expand Down
2 changes: 1 addition & 1 deletion pkg/harvester-manager/machine-config/harvester.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import draggable from 'vuedraggable';
import isEmpty from 'lodash/isEmpty';
import jsyaml from 'js-yaml';
import YAML from 'yaml';
import isBase64 from 'is-base64';
import { isBase64 } from '@shell/utils/string';
import NodeAffinity from '@shell/components/form/NodeAffinity';
import PodAffinity from '@shell/components/form/PodAffinity';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<script>
import { clone } from '@shell/utils/object';
import ArrayListGrouped from '@shell/components/form/ArrayListGrouped';
import { LabeledInput } from '@components/Form/LabeledInput';
import { Checkbox } from '@components/Form/Checkbox';
import SelectOrCreateAuthSecret from '@shell/components/form/SelectOrCreateAuthSecret';
import CreateEditView from '@shell/mixins/create-edit-view';
import SecretSelector from '@shell/components/form/SecretSelector';
import { SECRET_TYPES as TYPES } from '@shell/config/secret';
import { isBase64 } from '@shell/utils/string';
import { base64Decode, base64Encode } from '@shell/utils/crypto';
export default {
Expand Down Expand Up @@ -42,7 +44,7 @@ export default {
},
data() {
const configMap = this.value.spec.rkeConfig?.registries?.configs || {};
const configMap = clone(this.value.spec.rkeConfig?.registries?.configs) || {};
const entries = [];
const defaultAddValue = {
Expand All @@ -57,7 +59,11 @@ export default {
if (configMap[hostname]) {
configMap[hostname].insecureSkipVerify = configMap[hostname].insecureSkipVerify ?? defaultAddValue.insecureSkipVerify;
configMap[hostname].authConfigSecretName = configMap[hostname].authConfigSecretName ?? defaultAddValue.authConfigSecretName;
configMap[hostname].caBundle = base64Decode(configMap[hostname].caBundle ?? defaultAddValue.caBundle);
const caBundle = configMap[hostname].caBundle ?? defaultAddValue.caBundle;
configMap[hostname].caBundle = isBase64(caBundle) ? base64Decode(caBundle) : caBundle;
configMap[hostname].tlsSecretName = configMap[hostname].tlsSecretName ?? defaultAddValue.tlsSecretName;
}
entries.push({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ describe('component: RegistryConfigs', () => {
};

describe('key CA Cert Bundle', () => {
it('should display default key', () => {
it.each([
['source is plain text', 'Zm9vYmFy', 'foobar'],
['source is base64', 'foobar', 'foobar'],
])('should display key, %p', (_, sourceCaBundle, displayedCaBundle) => {
const value = clone(PROV_CLUSTER);

value.spec.rkeConfig.registries.configs = { foo: { caBundle: 'Zm9vYmFy' } };
value.spec.rkeConfig.registries.configs = { foo: { caBundle: sourceCaBundle } };

mountOptions.propsData.value = value;

Expand All @@ -37,7 +40,7 @@ describe('component: RegistryConfigs', () => {

const registry = wrapper.findComponent('[data-testid^="registry-caBundle"]');

expect(registry.props().value).toBe('foobar');
expect(registry.props().value).toBe(displayedCaBundle);
});

it('should update key in base64 format', async() => {
Expand Down
6 changes: 6 additions & 0 deletions shell/utils/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,9 @@ export function sanitizeIP(v) {
export function xOfy(x, y) {
return `${ typeof x === 'number' ? x : '?' }/${ typeof y === 'number' ? y : '?' }`;
}

export function isBase64(value) {
const base64regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;

return base64regex.test(value);
}
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9675,11 +9675,6 @@ is-arrayish@^0.3.1:
resolved "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.3.2.tgz#4574a2ae56f7ab206896fb431eaeed066fdf8f03"
integrity sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ==

[email protected]:
version "1.1.0"
resolved "https://registry.npmjs.org/is-base64/-/is-base64-1.1.0.tgz#8ce1d719895030a457c59a7dcaf39b66d99d56b4"
integrity sha512-Nlhg7Z2dVC4/PTvIFkgVVNvPHSO2eR/Yd0XzhGiXCXEvWnptXlXa/clQ8aePPiMuxEGcWfzWbGw2Fe3d+Y3v1g==

is-bigint@^1.0.1:
version "1.0.4"
resolved "https://registry.npmjs.org/is-bigint/-/is-bigint-1.0.4.tgz#08147a1875bc2b32005d41ccd8291dffc6691df3"
Expand Down

0 comments on commit a2bf86d

Please sign in to comment.