Skip to content

Commit 958d8bc

Browse files
Address pgweb feedback (#331)
Addresses feedback left on #329 Also downgrades to pgweb user and shows a disabled prompt when attempting to access an aurora database in another region <img width="1856" height="1681" alt="image" src="https://github.com/user-attachments/assets/41b15d55-d570-45a6-89e0-e2cb3b5dbfea" />
1 parent 999017d commit 958d8bc

6 files changed

Lines changed: 45 additions & 17 deletions

File tree

src/pgweb/.devcontainer.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,10 @@
1313
],
1414
"postStartCommand": "/workspace/start-bookmark-refresh.sh",
1515
"features": {
16-
"ghcr.io/devcontainers/features/common-utils:2": {
17-
"installZsh": false,
18-
"installOhMyZsh": false,
19-
"upgradePackages": false
20-
},
21-
"ghcr.io/devcontainers/features/java:1": {
16+
"ghcr.io/devcontainers/features/java@sha256:e75d274ac969b29a59ba6f34c2d098f6a52144d0ec027ef326b724ea4b8b7b4e": {
2217
"version": "17"
2318
},
24-
"ghcr.io/devcontainers/features/aws-cli:1": {}
19+
"ghcr.io/devcontainers/features/aws-cli@sha256:bbc9fd513c22e331953126c75ad7b2ed1f9044f1cd5890b7073b634810459b18": {}
2520
},
2621
"remoteUser": "root"
2722
}

src/pgweb/Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM sosedoff/pgweb
2+
3+
USER root
4+
5+
RUN apt-get update && \
6+
apt-get -y install sudo && \
7+
apt-get -y clean && \
8+
rm -rf /var/lib/apt/lists/* && \
9+
mkdir -p /pgweb && \
10+
chown pgweb:pgweb /pgweb
11+
12+
USER pgweb

src/pgweb/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Once deployed in Workbench, access the pgweb UI at the app URL (port 8081).
1818

1919
The app automatically discovers all Aurora databases in your Workbench workspace and creates pre-configured connection bookmarks with fresh IAM authentication tokens.
2020

21+
For more information on how pgweb bookmarks work, see [Server Connection
22+
Bookmarks](https://github.com/sosedoff/pgweb/wiki/Server-Connection-Bookmarks).
23+
2124
### How It Works
2225

2326
1. **Auto-Discovery**: Every 10 minutes, the app queries `wb resource list` to find all Aurora databases

src/pgweb/docker-compose.yaml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@ services:
33
# The container name must be "application-server"
44
container_name: "application-server"
55
# This can be either a pre-existing image or built from a Dockerfile
6-
image: "sosedoff/pgweb"
7-
# build:
8-
# context: .
9-
# Override the default entrypoint to use our custom script
10-
entrypoint: []
11-
command: ["pgweb", "--sessions", "--bind=0.0.0.0", "--listen=8081", "--bookmarks-dir=/root/.pgweb/bookmarks"]
12-
user: "root"
6+
build:
7+
context: .
8+
command: ["--sessions", "--bookmarks-dir=/pgweb/bookmarks"]
139
restart: always
1410
volumes:
1511
- .:/workspace:cached

src/pgweb/refresh-bookmarks.sh

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,22 @@ set -o nounset
55

66
# Allow overriding via environment for local testing
77
readonly WB_EXE="${WB_EXE:-/usr/bin/wb}"
8-
readonly PGWEB_BASE="${PGWEB_BASE:-/root/.pgweb}"
8+
readonly PGWEB_BASE="${PGWEB_BASE:-/pgweb}"
99
readonly BOOKMARK_DIR="${PGWEB_BASE}/bookmarks"
1010

1111
# Create base directory if it doesn't exist
1212
mkdir -p "${PGWEB_BASE}"
1313

14+
# Helper function to get AWS region
15+
get_region() {
16+
local imds_token
17+
imds_token="$(wget --method=PUT --header "X-aws-ec2-metadata-token-ttl-seconds:600" -q -O - http://169.254.169.254/latest/api/token)"
18+
local region
19+
region="$(wget --header "X-aws-ec2-metadata-token: ${imds_token}" -q -O - http://169.254.169.254/latest/meta-data/placement/region)"
20+
21+
echo "${region}"
22+
}
23+
1424
# Helper function to get credentials and generate IAM auth token
1525
generate_iam_token() {
1626
local resource_id="${1}"
@@ -76,6 +86,10 @@ refresh_bookmarks() {
7686
RESOURCES=$(${WB_EXE} resource list --format json)
7787
readonly RESOURCES
7888

89+
local VM_REGION
90+
VM_REGION=$(get_region)
91+
readonly VM_REGION
92+
7993
# Process each resource
8094
echo "${RESOURCES}" | jq -c '.[]' | while read -r resource; do
8195
local RESOURCE_TYPE
@@ -119,6 +133,12 @@ refresh_bookmarks() {
119133
continue
120134
fi
121135

136+
if [[ "${REGION}" != "${VM_REGION}" ]]; then
137+
echo " Resource region (${REGION}) does not match VM region (${VM_REGION}), skipping"
138+
touch "${TEMP_DIR}/${RESOURCE_ID} (Disabled - Cross Region).toml"
139+
continue
140+
fi
141+
122142
# Try to create READ_ONLY bookmark
123143
echo " Checking read access..."
124144
local RO_TOKEN

src/pgweb/start-bookmark-refresh.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ set -o errexit
33
set -o pipefail
44
set -o nounset
55

6+
readonly PGWEB_BASE="${PGWEB_BASE:-/pgweb}"
7+
68
echo "Starting bookmark refresh for pgweb..."
79

810
# Create base directory (but not bookmarks subdirectory - that will be a symlink)
9-
mkdir -p /root/.pgweb
11+
mkdir -p "${PGWEB_BASE}"
1012

1113
# Make sure refresh script is executable
1214
chmod +x /workspace/refresh-bookmarks.sh
@@ -24,7 +26,7 @@ nohup bash -c '
2426
sleep 600 # 10 minutes
2527
/workspace/refresh-bookmarks.sh || echo "$(date): WARNING: Bookmark refresh failed"
2628
done
27-
' >> /root/.pgweb/refresh.log 2>&1 &
29+
' >> "${PGWEB_BASE}/refresh.log" 2>&1 &
2830

2931
REFRESH_PID=$!
3032
echo "Bookmark refresh service configured (background PID: ${REFRESH_PID})"

0 commit comments

Comments
 (0)