Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ type EnvironmentConfig struct {
Clickhouse ClickhouseConfig `yaml:"clickhouse"`
Fluentbit FluentbitConfig `yaml:"fluentbit"`
Nginx NginxConfig `yaml:"nginx"`

HostUID int `yaml:"-"`
HostGID int `yaml:"-"`
Comment thread
dvasilas marked this conversation as resolved.
}

type GlobalConfig struct {
Expand Down Expand Up @@ -319,6 +322,8 @@ func DefaultEnvironmentConfig() EnvironmentConfig {

func LoadEnvironmentConfig(path string) (EnvironmentConfig, error) {
cfg := DefaultEnvironmentConfig()
cfg.HostUID = os.Getuid()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember messing around with this but it was for the logs/volumes with the host, anything related to CRR in this case?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to CRR, just a side-fix for an issue I noticed (705326d).

It is about file permissions in volumes on the host.
Because containers run as root, files in volumes are owned by root and need sudo to rm.

cfg.HostGID = os.Getgid()

if path == "" {
return cfg, nil
Expand Down
1 change: 1 addition & 0 deletions cmd/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ func generateBackbeatConfig(cfg EnvironmentConfig, path string) error {
"config.json",
"config.notification.json",
"notificationCredentials.json",
"admin-backbeat.json",
}

return renderTemplates(cfg, "templates/backbeat", filepath.Join(path, "backbeat"), templates)
Expand Down
102 changes: 102 additions & 0 deletions scripts/enable-crr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/usr/bin/env bash
# enable-crr.sh — create source + destination buckets and configure replication.
#
# Usage:
# scripts/enable-crr.sh --source <bucket> --destination <bucket> \
# [--prefix <pfx>] [--endpoint <url>]
#
# Defaults:
# --endpoint http://127.0.0.1:8000
# --prefix "" (replicate everything)
#
# Idempotent: re-running is a no-op once resources exist.

set -eu

# Pinned to match templates/vault/create-management-account.sh and the
# replication-role accountSeed in templates/vault/config.json.
ROLE_ARN="arn:aws:iam::123456789012:role/scality-internal/replication-role"

SOURCE=""
DESTINATION=""
PREFIX=""
ENDPOINT="http://127.0.0.1:8000"

while [ $# -gt 0 ]; do
case "$1" in
--source) SOURCE="$2"; shift 2 ;;
--destination) DESTINATION="$2"; shift 2 ;;
--prefix) PREFIX="$2"; shift 2 ;;
--endpoint) ENDPOINT="$2"; shift 2 ;;
-h|--help)
sed -n '2,12p' "$0" | sed 's/^# \{0,1\}//'
exit 0
;;
*) echo "unknown flag: $1" >&2; exit 2 ;;
esac
done

if [ -z "$SOURCE" ] || [ -z "$DESTINATION" ]; then
echo "error: --source and --destination are required" >&2
exit 2
fi

# testaccount credentials are fixed in templates/vault/create-management-account.sh
export AWS_ACCESS_KEY_ID="WBTKACCESSI9O3YKIRQ0"
export AWS_SECRET_ACCESS_KEY="ICxmNTBbOqijy4rMq/MOP1EPlTMqfsEBLjROcAbN"
export AWS_DEFAULT_REGION="us-east-1"

AWS="aws --endpoint-url $ENDPOINT"

create_bucket() {
local bucket="$1"
if $AWS s3api create-bucket --bucket "$bucket" >/dev/null 2>&1; then
echo "[crr] created bucket $bucket"
else
# swallow "already exists and owned by you" — treat anything else as fatal
if $AWS s3api head-bucket --bucket "$bucket" >/dev/null 2>&1; then
echo "[crr] bucket $bucket already exists"
else
echo "error: failed to create bucket $bucket" >&2
$AWS s3api create-bucket --bucket "$bucket"
exit 1
fi
fi
}

enable_versioning() {
local bucket="$1"
$AWS s3api put-bucket-versioning \
--bucket "$bucket" \
--versioning-configuration Status=Enabled
echo "[crr] versioning enabled on $bucket"
}

create_bucket "$SOURCE"
create_bucket "$DESTINATION"
enable_versioning "$SOURCE"
enable_versioning "$DESTINATION"

REPLICATION_CONFIG=$(cat <<EOF
{
"Role": "${ROLE_ARN},${ROLE_ARN}",
"Rules": [
{
"ID": "workbench-crr",
"Status": "Enabled",
"Prefix": "${PREFIX}",
"Destination": {
"Bucket": "arn:aws:s3:::${DESTINATION}",
"StorageClass": "sf"
}
}
]
}
EOF
)

$AWS s3api put-bucket-replication \
--bucket "$SOURCE" \
--replication-configuration "$REPLICATION_CONFIG"

echo "[crr] replication configured: $SOURCE -> $DESTINATION (prefix='$PREFIX')"
1 change: 1 addition & 0 deletions templates/backbeat/admin-backbeat.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"D4IT2AWSB588GO5J9T00":"UEEu8tYlsOGGrgf4DAiSZD6apVNPUWqRiPG0nTB6"}
10 changes: 7 additions & 3 deletions templates/backbeat/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
"host": "127.0.0.1",
"port": 8500
},
"redis": {
"host": "127.0.0.1",
"port": 6379
},
"replicationGroupId": "RG001 ",
"queuePopulator": {
"cronRule": "*/5 * * * * *",
Expand Down Expand Up @@ -59,7 +63,7 @@
"host": "127.0.0.1",
"port": 8500,
"adminPort": 8600,
"adminCredentialsFile": "/home/scality/backbeat/node_modules/vaultclient/tests/utils/admincredentials.json"
"adminCredentialsFile": "/conf/admin-backbeat.json"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the diff between the two? or was there some permissions issue?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the same content, I just thought it's a bit better for future readers to have the file here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alrighty

}
}
},
Expand All @@ -74,7 +78,7 @@
"host": "127.0.0.1",
"port": 8500,
"adminPort": 8600,
"adminCredentialsFile": "/home/scality/backbeat/node_modules/vaultclient/tests/utils/admincredentials.json"
"adminCredentialsFile": "/conf/admin-backbeat.json"
}
}
},
Expand Down Expand Up @@ -176,7 +180,7 @@
"port": 8500
}
},
"backlogControl": { "enabled": true },
"backlogControl": { "enabled": false },
"cronRule": "*/5 * * * * *",
"concurrency": 10,
"bucketSource": "bucketd",
Expand Down
3 changes: 3 additions & 0 deletions templates/global/defaults.env
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ NGINX_IMAGE="{{ .Nginx.Image }}"

METADATA_S3_DB_VERSION="{{ .S3Metadata.VFormat }}"
CLOUDSERVER_ENABLE_NULL_VERSION_COMPAT_MODE="{{ .Cloudserver.EnableNullVersionCompatMode }}"

HOST_UID="{{ .HostUID }}"
HOST_GID="{{ .HostGID }}"
9 changes: 8 additions & 1 deletion templates/global/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ services:
BASE_IMAGE: ${VAULT_IMAGE}
container_name: workbench-setup-vault
network_mode: host
user: "${HOST_UID}:${HOST_GID}"
volumes:
- ./config/vault/management-creds.json:/conf/management-creds.json:ro
- ./config/backbeat:/conf/backbeat:rw
Expand Down Expand Up @@ -166,6 +167,7 @@ services:
BASE_IMAGE: ${SCUBA_IMAGE}
container_name: workbench-setup-scuba
network_mode: host
user: "${HOST_UID}:${HOST_GID}"
depends_on:
setup-vault:
condition: service_completed_successfully
Expand All @@ -181,13 +183,18 @@ services:
depends_on:
setup-vault:
condition: service_completed_successfully
setup-kafka:
condition: service_completed_successfully
Comment thread
dvasilas marked this conversation as resolved.
Comment thread
dvasilas marked this conversation as resolved.
redis:
condition: service_healthy
environment:
SUPERVISORD_CONF: supervisord.conf
BACKBEAT_CONFIG_FILE: /conf/config.json
volumes:
- ./config/backbeat/supervisord.conf:/conf/supervisord.conf:ro
- ./config/backbeat/config.json:/conf/config.json:ro
- ./config/backbeat/config.notification.json:/conf/config.notification.json:ro
- ./config/backbeat/admin-backbeat.json:/conf/admin-backbeat.json:ro
- ./config/backbeat/env:/conf/env:ro
- ./logs/backbeat:/logs
profiles:
Expand Down Expand Up @@ -260,7 +267,7 @@ services:
backbeat-data-mover
backbeat-replication-status
backbeat-replication-failed
backbeat-metrics-group-crr
backbeat-metrics
CREATE_ZOOKEEPER_PATHS: 'true'
ZOOKEEPER_ENDPOINT: 127.0.0.1:2181/backbeat
depends_on:
Expand Down
6 changes: 5 additions & 1 deletion templates/kafka/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ if [[ "$CREATE_ZOOKEEPER_PATHS" == "true" ]]; then
fi

echo "[setup] Creating Zookeeper paths..."
# zookeeper-shell.sh exits non-zero when any 'create' returns NodeExists,
# which is the expected outcome on re-runs against a persisted volume.
set +e
zookeeper-shell.sh localhost:2181/backbeat <<EOF
create /
create /bucket-notification
Expand All @@ -61,14 +64,15 @@ create /queue-populator/raft-id-dispatcher
create /queue-populator/raft-id-dispatcher/owners
create /queue-populator/raft-id-dispatcher/leaders
create /queue-populator/raft-id-dispatcher/provisions
create /queue-populator/raft-id-dispatcher/provisions/0
create /queue-populator/raft-id-dispatcher/provisions/1
create /queue-populator/raft-id-dispatcher/provisions/2
create /queue-populator/raft-id-dispatcher/provisions/3
create /lifecycle
create /lifecycle/conductor
create /lifecycle/conductor/election
quit
EOF
set -e
echo "[setup] Zookeeper paths created."
echo
fi
32 changes: 32 additions & 0 deletions templates/vault/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,38 @@
]
}
}
},
{
"role": {
"roleName": "replication-role",
"trustPolicy": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::000000000000:user/root"
},
"Action": "sts:AssumeRole",
"Condition": {}
}
]
}
},
"permissionPolicy": {
"policyName": "replication-policy",
"policyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ReplicationFullAccess",
"Effect": "Allow",
"Action": ["s3:*"],
"Resource": ["*"]
}
]
}
}
}
],
"utapi": {
Expand Down
9 changes: 7 additions & 2 deletions templates/vault/create-management-account.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,20 @@ fi
echo "[setup] Management account and access key setup completed successfully"

# === Create test data account ===
# This account is seeded with the lifecycle role via vault's accountSeeds,
# which allows backbeat to AssumeRole into it for lifecycle operations.
# This account is seeded with the lifecycle and replication roles via vault's
# accountSeeds. We pin the account ID so downstream tooling (e.g. the
# enable-crr.sh helper) can reference role ARNs in this account by a stable
# value.
TEST_ACCOUNT_ACCESS_KEY="WBTKACCESSI9O3YKIRQ0"
TEST_ACCOUNT_SECRET_KEY="ICxmNTBbOqijy4rMq/MOP1EPlTMqfsEBLjROcAbN"
TEST_ACCOUNT_ID="123456789012"

echo "[setup] Creating test data account..."
resp=$(./node_modules/vaultclient/bin/vaultclient \
create-account \
--name testaccount \
--email testaccount@test.com \
--accountid "$TEST_ACCOUNT_ID" \
--host 127.0.0.1 \
--port 8600 2>&1) || {
if echo "$resp" | grep -q "EntityAlreadyExists"; then
Expand Down Expand Up @@ -221,6 +225,7 @@ if [ -f "$BACKBEAT_CONFIG_FILE" ]; then

mv /tmp/backbeat-config.updated.json "$BACKBEAT_CONFIG_FILE"
echo "[setup] Backbeat config.json updated with lifecycle credentials"

fi

echo "[setup] Setup completed successfully"
Loading