Skip to content

Commit df78e29

Browse files
FEATURE (s3): Allow to skip TLS verification
1 parent fda3bf9 commit df78e29

File tree

6 files changed

+79
-4
lines changed

6 files changed

+79
-4
lines changed

backend/internal/features/storages/models/s3/model.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package s3_storage
33
import (
44
"bytes"
55
"context"
6+
"crypto/tls"
67
"errors"
78
"fmt"
89
"io"
@@ -40,6 +41,7 @@ type S3Storage struct {
4041

4142
S3Prefix string `json:"s3Prefix" gorm:"type:text;column:s3_prefix"`
4243
S3UseVirtualHostedStyle bool `json:"s3UseVirtualHostedStyle" gorm:"default:false;column:s3_use_virtual_hosted_style"`
44+
SkipTLSVerify bool `json:"skipTLSVerify" gorm:"default:false;column:skip_tls_verify"`
4345
}
4446

4547
func (s *S3Storage) TableName() string {
@@ -331,6 +333,7 @@ func (s *S3Storage) Update(incoming *S3Storage) {
331333
s.S3Region = incoming.S3Region
332334
s.S3Endpoint = incoming.S3Endpoint
333335
s.S3UseVirtualHostedStyle = incoming.S3UseVirtualHostedStyle
336+
s.SkipTLSVerify = incoming.SkipTLSVerify
334337

335338
if incoming.S3AccessKey != "" {
336339
s.S3AccessKey = incoming.S3AccessKey
@@ -442,6 +445,9 @@ func (s *S3Storage) getClientParams(
442445
TLSHandshakeTimeout: s3TLSHandshakeTimeout,
443446
ResponseHeaderTimeout: s3ResponseTimeout,
444447
IdleConnTimeout: s3IdleConnTimeout,
448+
TLSClientConfig: &tls.Config{
449+
InsecureSkipVerify: s.SkipTLSVerify,
450+
},
445451
}
446452

447453
return endpoint, useSSL, accessKey, secretKey, bucketLookup, transport, nil
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- +goose Up
2+
-- +goose StatementBegin
3+
ALTER TABLE s3_storages
4+
ADD COLUMN skip_tls_verify BOOLEAN NOT NULL DEFAULT FALSE;
5+
-- +goose StatementEnd
6+
7+
-- +goose Down
8+
-- +goose StatementBegin
9+
ALTER TABLE s3_storages
10+
DROP COLUMN skip_tls_verify;
11+
-- +goose StatementEnd

frontend/src/entity/storages/models/S3Storage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ export interface S3Storage {
66
s3Endpoint?: string;
77
s3Prefix?: string;
88
s3UseVirtualHostedStyle?: boolean;
9+
skipTLSVerify?: boolean;
910
}

frontend/src/features/storages/ui/edit/EditStorageComponent.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export function EditStorageComponent({
3939

4040
const [isTestingConnection, setIsTestingConnection] = useState(false);
4141
const [isTestConnectionSuccess, setIsTestConnectionSuccess] = useState(false);
42+
const [connectionError, setConnectionError] = useState<string | undefined>();
4243

4344
const save = async () => {
4445
if (!storage) return;
@@ -60,6 +61,7 @@ export function EditStorageComponent({
6061
if (!storage) return;
6162

6263
setIsTestingConnection(true);
64+
setConnectionError(undefined);
6365

6466
try {
6567
await storageApi.testStorageConnectionDirect(storage);
@@ -69,7 +71,9 @@ export function EditStorageComponent({
6971
description: 'Storage connection tested successfully',
7072
});
7173
} catch (e) {
72-
alert((e as Error).message);
74+
const errorMessage = (e as Error).message;
75+
setConnectionError(errorMessage);
76+
alert(errorMessage);
7377
}
7478

7579
setIsTestingConnection(false);
@@ -290,7 +294,9 @@ export function EditStorageComponent({
290294
setUnsaved={() => {
291295
setIsUnsaved(true);
292296
setIsTestConnectionSuccess(false);
297+
setConnectionError(undefined);
293298
}}
299+
connectionError={connectionError}
294300
/>
295301
)}
296302

frontend/src/features/storages/ui/edit/storages/EditS3StorageComponent.tsx

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
11
import { DownOutlined, InfoCircleOutlined, UpOutlined } from '@ant-design/icons';
22
import { Checkbox, Input, Tooltip } from 'antd';
3-
import { useState } from 'react';
3+
import { useEffect, useState } from 'react';
44

55
import type { Storage } from '../../../../../entity/storages';
66

77
interface Props {
88
storage: Storage;
99
setStorage: (storage: Storage) => void;
1010
setUnsaved: () => void;
11+
connectionError?: string;
1112
}
1213

13-
export function EditS3StorageComponent({ storage, setStorage, setUnsaved }: Props) {
14+
export function EditS3StorageComponent({
15+
storage,
16+
setStorage,
17+
setUnsaved,
18+
connectionError,
19+
}: Props) {
1420
const hasAdvancedValues =
15-
!!storage?.s3Storage?.s3Prefix || !!storage?.s3Storage?.s3UseVirtualHostedStyle;
21+
!!storage?.s3Storage?.s3Prefix ||
22+
!!storage?.s3Storage?.s3UseVirtualHostedStyle ||
23+
!!storage?.s3Storage?.skipTLSVerify;
1624
const [showAdvanced, setShowAdvanced] = useState(hasAdvancedValues);
1725

26+
useEffect(() => {
27+
if (connectionError?.includes('failed to verify certificate')) {
28+
setShowAdvanced(true);
29+
}
30+
}, [connectionError]);
31+
1832
return (
1933
<>
2034
<div className="mb-2 flex items-center">
@@ -226,6 +240,36 @@ export function EditS3StorageComponent({ storage, setStorage, setUnsaved }: Prop
226240
</Tooltip>
227241
</div>
228242
</div>
243+
244+
<div className="mb-1 flex w-full flex-col items-start sm:flex-row sm:items-center">
245+
<div className="mb-1 min-w-[110px] sm:mb-0">Skip TLS verify</div>
246+
<div className="flex items-center">
247+
<Checkbox
248+
checked={storage?.s3Storage?.skipTLSVerify || false}
249+
onChange={(e) => {
250+
if (!storage?.s3Storage) return;
251+
252+
setStorage({
253+
...storage,
254+
s3Storage: {
255+
...storage.s3Storage,
256+
skipTLSVerify: e.target.checked,
257+
},
258+
});
259+
setUnsaved();
260+
}}
261+
>
262+
Skip TLS
263+
</Checkbox>
264+
265+
<Tooltip
266+
className="cursor-pointer"
267+
title="Skip TLS certificate verification. Enable this if your S3-compatible storage uses a self-signed certificate. Warning: this reduces security."
268+
>
269+
<InfoCircleOutlined className="ml-2" style={{ color: 'gray' }} />
270+
</Tooltip>
271+
</div>
272+
</div>
229273
</>
230274
)}
231275

frontend/src/features/storages/ui/show/storages/ShowS3StorageComponent.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ export function ShowS3StorageComponent({ storage }: Props) {
4545
Enabled
4646
</div>
4747
)}
48+
49+
{storage?.s3Storage?.skipTLSVerify && (
50+
<div className="mb-1 flex items-center">
51+
<div className="min-w-[110px]">Skip TLS</div>
52+
Enabled
53+
</div>
54+
)}
4855
</>
4956
);
5057
}

0 commit comments

Comments
 (0)