Skip to content

Commit f375df3

Browse files
authored
fixes YDB authorization (#159)
* fix context withTimeout * fix lint errors * fix e2e tests Makefile running * fix runSelfCheck * fix sync reconcile * fix e2e tests * increase go test timeout * increase timeout smoke test * docker-build-push github task use path context * fix database event recorder * fix database configmap owner * e2e test with staticCreds
1 parent 433ec18 commit f375df3

File tree

18 files changed

+409
-244
lines changed

18 files changed

+409
-244
lines changed

.github/workflows/run-tests.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
user: yc-admin
3232
ssh-public-key: ${{ secrets.CI_RUNNER_DEBUG_SHH_PUBLIC_KEY }}
3333
smart-checkout:
34-
needs:
34+
needs:
3535
- start-runner
3636
runs-on: ${{ needs.start-runner.outputs.runner-label }}
3737
steps:
@@ -47,7 +47,7 @@ jobs:
4747
concurrency:
4848
group: lint-golangci-${{ github.ref }}
4949
cancel-in-progress: true
50-
needs:
50+
needs:
5151
- start-runner
5252
- smart-checkout
5353
runs-on: ${{ needs.start-runner.outputs.runner-label }}
@@ -67,7 +67,7 @@ jobs:
6767
concurrency:
6868
group: lint-autoformat-${{ github.ref }}
6969
cancel-in-progress: true
70-
needs:
70+
needs:
7171
- start-runner
7272
- smart-checkout
7373
runs-on: ${{ needs.start-runner.outputs.runner-label }}
@@ -88,7 +88,7 @@ jobs:
8888
- name: Check repository diff
8989
run: bash ./.github/scripts/check-work-copy-equals-to-committed.sh "auto-format broken"
9090
run-tests:
91-
needs:
91+
needs:
9292
- start-runner
9393
- smart-checkout
9494
runs-on: ${{ needs.start-runner.outputs.runner-label }}
@@ -135,7 +135,7 @@ jobs:
135135
helm version
136136
- name: setup-medium-test-class-binaries
137137
run: |
138-
# This installs kube-apiserver and etcd binaries for `medium`
138+
# This installs kube-apiserver and etcd binaries for `medium`
139139
# class tests. Refer to the writing tests docs for more info.
140140
make envtest
141141
KUBEBUILDER_ASSETS=$(./bin/setup-envtest use 1.26 -p path)

Makefile

+5-3
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ vet: ## Run go vet against code.
6464
test: manifests generate fmt vet envtest docker-build ## Run tests.
6565
kind create cluster --config e2e/kind-cluster-config.yaml --name kind-ydb-operator
6666
docker tag cr.yandex/yc/ydb-operator:latest kind/ydb-operator:current
67-
kind load docker-image cr.yandex/yc/ydb-operator:latest --name kind-ydb-operator
68-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out
67+
kind load docker-image kind/ydb-operator:current --name kind-ydb-operator
68+
docker pull cr.yandex/crptqonuodf51kdj7a7d/ydb:22.4.44
69+
kind load docker-image cr.yandex/crptqonuodf51kdj7a7d/ydb:22.4.44 --name kind-ydb-operator
70+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test -timeout 1800s -p 1 ./... -coverprofile cover.out
6971

7072
.PHONY: clean
7173
clean:
@@ -77,7 +79,7 @@ build: generate fmt vet ## Build manager binary.
7779
go build -o bin/manager cmd/ydb-kubernetes-operator/main.go
7880

7981
docker-build: ## Build docker image with the manager.
80-
docker build -t ${IMG} .
82+
docker build --network=host -t ${IMG} .
8183

8284
docker-push: ## Push docker image with the manager.
8385
docker push ${IMG}

api/v1alpha1/storage_webhook.go

+35-20
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,19 @@ func (r *Storage) SetupWebhookWithManager(mgr ctrl.Manager) error {
2121
Complete()
2222
}
2323

24-
type DomainsConfig struct {
25-
SecurityConfig struct {
26-
EnforceUserTokenRequirement bool `yaml:"enforce_user_token_requirement"`
27-
} `yaml:"security_config"`
28-
}
29-
3024
//+kubebuilder:webhook:path=/mutate-ydb-tech-v1alpha1-storage,mutating=true,failurePolicy=fail,sideEffects=None,groups=ydb.tech,resources=storages,verbs=create;update,versions=v1alpha1,name=mutate-storage.ydb.tech,admissionReviewVersions=v1
3125

3226
var _ webhook.Defaulter = &Storage{}
3327

28+
// +k8s:deepcopy-gen=false
29+
type PartialYamlConfig struct {
30+
DomainsConfig struct {
31+
SecurityConfig struct {
32+
EnforceUserTokenRequirement bool `yaml:"enforce_user_token_requirement"`
33+
} `yaml:"security_config"`
34+
} `yaml:"domains_config"`
35+
}
36+
3437
// Default implements webhook.Defaulter so a webhook will be registered for the type
3538
func (r *Storage) Default() {
3639
storagelog.Info("default", "name", r.Name)
@@ -90,13 +93,19 @@ func (r *Storage) ValidateCreate() error {
9093
nodesNumber = int32(len(hosts))
9194
}
9295

93-
if configuration["domains_config"] != nil {
94-
if domainsConfig, ok := configuration["domains_config"].(DomainsConfig); ok {
95-
authEnabled := domainsConfig.SecurityConfig.EnforceUserTokenRequirement
96-
if (authEnabled && r.Spec.OperatorConnection == nil) || (!authEnabled && r.Spec.OperatorConnection != nil) {
97-
return fmt.Errorf("field 'spec.operatorConnection' does not satisfy with config option `enforce_user_token_requirement: %t`", authEnabled)
98-
}
99-
}
96+
yamlConfig := PartialYamlConfig{}
97+
err = yaml.Unmarshal([]byte(r.Spec.Configuration), &yamlConfig)
98+
if err != nil {
99+
return fmt.Errorf("failed to parse YAML to determine `enforce_user_token_requirement`")
100+
}
101+
102+
var authEnabled bool
103+
if yamlConfig.DomainsConfig.SecurityConfig.EnforceUserTokenRequirement {
104+
authEnabled = true
105+
}
106+
107+
if (authEnabled && r.Spec.OperatorConnection == nil) || (!authEnabled && r.Spec.OperatorConnection != nil) {
108+
return fmt.Errorf("field 'spec.operatorConnection' does not satisfy with config option `enforce_user_token_requirement: %t`", authEnabled)
100109
}
101110

102111
minNodesPerErasure := map[ErasureType]int32{
@@ -144,13 +153,19 @@ func (r *Storage) ValidateUpdate(old runtime.Object) error {
144153
return fmt.Errorf("failed to parse Storage.spec.configuration, error: %w", err)
145154
}
146155

147-
if configuration["domains_config"] != nil {
148-
if domainsConfig, ok := configuration["domains_config"].(DomainsConfig); ok {
149-
authEnabled := domainsConfig.SecurityConfig.EnforceUserTokenRequirement
150-
if (authEnabled && r.Spec.OperatorConnection == nil) || (!authEnabled && r.Spec.OperatorConnection != nil) {
151-
return fmt.Errorf("field 'spec.operatorConnection' does not satisfy with config option `enforce_user_token_requirement: %t`", authEnabled)
152-
}
153-
}
156+
yamlConfig := PartialYamlConfig{}
157+
err = yaml.Unmarshal([]byte(r.Spec.Configuration), &yamlConfig)
158+
if err != nil {
159+
return fmt.Errorf("failed to parse YAML to determine `enforce_user_token_requirement`")
160+
}
161+
162+
var authEnabled bool
163+
if yamlConfig.DomainsConfig.SecurityConfig.EnforceUserTokenRequirement {
164+
authEnabled = true
165+
}
166+
167+
if (authEnabled && r.Spec.OperatorConnection == nil) || (!authEnabled && r.Spec.OperatorConnection != nil) {
168+
return fmt.Errorf("field 'spec.operatorConnection' does not satisfy with config option `enforce_user_token_requirement: %t`", authEnabled)
154169
}
155170

156171
crdCheckError := checkMonitoringCRD(manager, storagelog, r.Spec.Monitoring != nil)

api/v1alpha1/zz_generated.deepcopy.go

-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deploy/ydb-operator/Chart.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ type: application
1515
# This is the chart version. This version number should be incremented each time you make changes
1616
# to the chart and its templates, including the app version.
1717
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18-
version: 0.4.34
18+
version: 0.4.35
1919

2020
# This is the version number of the application being deployed. This version number should be
2121
# incremented each time you make changes to the application. Versions are not expected to
2222
# follow Semantic Versioning. They should reflect the version the application is using.
2323
# It is recommended to use it with quotes.
24-
appVersion: "0.4.34"
24+
appVersion: "0.4.35"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
static_erasure: block-4-2
2+
host_configs:
3+
- drive:
4+
- path: SectorMap:1:1
5+
type: SSD
6+
host_config_id: 1
7+
domains_config:
8+
security_config:
9+
enforce_user_token_requirement: true
10+
domain:
11+
- name: Root
12+
storage_pool_types:
13+
- kind: ssd
14+
pool_config:
15+
box_id: 1
16+
erasure_species: block-4-2
17+
kind: ssd
18+
pdisk_filter:
19+
- property:
20+
- type: SSD
21+
vdisk_kind: Default
22+
state_storage:
23+
- ring:
24+
node: [1, 2, 3, 4, 5, 6, 7, 8]
25+
nto_select: 5
26+
ssid: 1
27+
table_service_config:
28+
sql_version: 1
29+
actor_system_config:
30+
executor:
31+
- name: System
32+
threads: 1
33+
type: BASIC
34+
- name: User
35+
threads: 1
36+
type: BASIC
37+
- name: Batch
38+
threads: 1
39+
type: BASIC
40+
- name: IO
41+
threads: 1
42+
time_per_mailbox_micro_secs: 100
43+
type: IO
44+
- name: IC
45+
spin_threshold: 10
46+
threads: 4
47+
time_per_mailbox_micro_secs: 100
48+
type: BASIC
49+
scheduler:
50+
progress_threshold: 10000
51+
resolution: 256
52+
spin_threshold: 0
53+
blob_storage_config:
54+
service_set:
55+
groups:
56+
- erasure_species: block-4-2
57+
rings:
58+
- fail_domains:
59+
- vdisk_locations:
60+
- node_id: storage-0
61+
pdisk_category: SSD
62+
path: SectorMap:1:1
63+
- vdisk_locations:
64+
- node_id: storage-1
65+
pdisk_category: SSD
66+
path: SectorMap:1:1
67+
- vdisk_locations:
68+
- node_id: storage-2
69+
pdisk_category: SSD
70+
path: SectorMap:1:1
71+
- vdisk_locations:
72+
- node_id: storage-3
73+
pdisk_category: SSD
74+
path: SectorMap:1:1
75+
- vdisk_locations:
76+
- node_id: storage-4
77+
pdisk_category: SSD
78+
path: SectorMap:1:1
79+
- vdisk_locations:
80+
- node_id: storage-5
81+
pdisk_category: SSD
82+
path: SectorMap:1:1
83+
- vdisk_locations:
84+
- node_id: storage-6
85+
pdisk_category: SSD
86+
path: SectorMap:1:1
87+
- vdisk_locations:
88+
- node_id: storage-7
89+
pdisk_category: SSD
90+
path: SectorMap:1:1
91+
channel_profile_config:
92+
profile:
93+
- channel:
94+
- erasure_species: block-4-2
95+
pdisk_category: 1
96+
storage_pool_kind: ssd
97+
- erasure_species: block-4-2
98+
pdisk_category: 1
99+
storage_pool_kind: ssd
100+
- erasure_species: block-4-2
101+
pdisk_category: 1
102+
storage_pool_kind: ssd
103+
profile_id: 0
104+
grpc_config:
105+
port: 2135

e2e/tests/data/storage-block-4-2-config.yaml

+12-16
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,16 @@ host_configs:
66
host_config_id: 1
77
domains_config:
88
domain:
9-
# There can be only one root domain in a cluster. Domain name prefixes all scheme objects names, e.g. full name of a table table1 in database db1
10-
# in a cluster with domains_config.domain.name parameter set to Root would be equal to /Root/db1/table1
119
- name: Root
1210
storage_pool_types:
1311
- kind: ssd
1412
pool_config:
1513
box_id: 1
16-
# fault tolerance mode name - none, block-4-2, or mirror-3-dc.
17-
# See docs for more details https://ydb.tech/en/docs/deploy/configuration/config#domains-blob
1814
erasure_species: block-4-2
1915
kind: ssd
2016
pdisk_filter:
2117
- property:
22-
- type: SSD # device type to match host_configs.drive.type
18+
- type: SSD
2319
vdisk_kind: Default
2420
state_storage:
2521
- ring:
@@ -29,34 +25,34 @@ domains_config:
2925
table_service_config:
3026
sql_version: 1
3127
actor_system_config:
32-
executor:
33-
- name: System
28+
executor:
29+
- name: System
3430
threads: 1
3531
type: BASIC
36-
- name: User
32+
- name: User
3733
threads: 1
3834
type: BASIC
39-
- name: Batch
40-
threads: 1
35+
- name: Batch
36+
threads: 1
4137
type: BASIC
42-
- name: IO
38+
- name: IO
4339
threads: 1
4440
time_per_mailbox_micro_secs: 100
4541
type: IO
46-
- name: IC
42+
- name: IC
4743
spin_threshold: 10
48-
threads: 4
44+
threads: 4
4945
time_per_mailbox_micro_secs: 100
5046
type: BASIC
5147
scheduler:
5248
progress_threshold: 10000
5349
resolution: 256
5450
spin_threshold: 0
55-
blob_storage_config: # configuration of static blobstorage group.
51+
blob_storage_config:
5652
service_set:
5753
groups:
58-
- erasure_species: block-4-2 # fault tolerance mode name for the static group
59-
rings: # in block-4-2 must have exactly 1 ring or availability zone.
54+
- erasure_species: block-4-2
55+
rings:
6056
- fail_domains:
6157
- vdisk_locations:
6258
- node_id: storage-0

0 commit comments

Comments
 (0)