Skip to content

Commit 7f42a40

Browse files
Fix SAS startup issues, WB CLI, and environment variables (#410)
* Get SAS running * WB CLI and AoU env variables * cleanup
1 parent 0171fa8 commit 7f42a40

11 files changed

Lines changed: 84 additions & 65 deletions

src/aou-sas/.devcontainer.json

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,7 @@
55
"runServices": ["app", "wondershaper"],
66
"shutdownAction": "none",
77
"workspaceFolder": "/workspace",
8-
"postCreateCommand": [
9-
"./startupscript/post-startup.sh",
10-
"aou",
11-
"/data",
12-
"${templateOption:cloud}",
13-
"${templateOption:login}"
14-
],
15-
"postStartCommand": [
16-
"./startupscript/remount-on-restart.sh",
17-
"aou",
18-
"/data",
19-
"${templateOption:cloud}",
20-
"${templateOption:login}"
21-
],
8+
"postCreateCommand": "./startupscript/post-startup.sh aou /data '${templateOption:cloud}' '${templateOption:login}' && ./setup-sas-env.sh aou /data",
9+
"postStartCommand": "./startupscript/remount-on-restart.sh aou /data '${templateOption:cloud}' '${templateOption:login}' && ./setup-sas-env.sh aou /data",
2210
"remoteUser": "root"
2311
}

src/aou-sas/Dockerfile

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,23 @@ USER root
66
# This must be in the Dockerfile because it references a build context (load-envs).
77
COPY --from=load-envs /dist/load-env /dist/load-env.sh /opt/sas/aou/
88

9-
###############################################################################
10-
# Package-manager compatibility
11-
# Workbench startup scripts (post-startup.sh, resource-mount.sh) expect
12-
# apt-get / apt. These shims delegate to yum on this RHEL-based SAS image.
13-
###############################################################################
14-
RUN printf '#!/bin/bash\ncase "$1" in\n update) exec yum makecache -y ;;\n install) shift; exec yum install -y --allowerasing "$@" ;;\n *) exec yum "$@" ;;\nesac\n' > /usr/local/bin/apt-get && \
15-
chmod +x /usr/local/bin/apt-get && \
16-
cp /usr/local/bin/apt-get /usr/local/bin/apt && \
17-
chmod +x /usr/local/bin/apt
18-
199
###############################################################################
2010
# Disable SAS-internal repos (unreachable outside SAS network) and enable
21-
# public UBI + EPEL repos so packages like jq, fuse, git can be resolved.
11+
# public UBI repos so packages like jq, fuse, git can be resolved.
2212
###############################################################################
2313
RUN dnf config-manager --set-disabled \
2414
crackles-epel-everything \
2515
sas-rhel-9-baseos sas-rhel-9-appstream sas-rhel-9-codeready \
2616
sas-ubi-9-baseos sas-ubi-9-appstream sas-ubi-9-codeready-builder && \
2717
dnf config-manager --set-enabled \
28-
ubi-9-baseos-rpms ubi-9-appstream-rpms ubi-9-codeready-builder-rpms && \
29-
rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm && \
30-
yum clean all
18+
ubi-9-baseos-rpms ubi-9-appstream-rpms ubi-9-codeready-builder-rpms
3119

3220
###############################################################################
3321
# System packages required by Workbench startup scripts
3422
###############################################################################
35-
RUN yum install -y --allowerasing curl fuse fuse-libs wget sudo git \
23+
RUN dnf install -y --allowerasing curl fuse fuse-libs wget sudo git \
3624
java-17-openjdk-headless && \
37-
yum clean all
38-
39-
###############################################################################
40-
# gcsfuse — GCS bucket mounting
41-
###############################################################################
42-
RUN printf '[gcsfuse]\nname=gcsfuse (packages.cloud.google.com)\nbaseurl=https://packages.cloud.google.com/yum/repos/gcsfuse-el7-x86_64\nenabled=1\ngpgcheck=1\nrepo_gpgcheck=0\ngpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg\n https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg\n' > /etc/yum.repos.d/gcsfuse.repo && \
43-
yum install -y gcsfuse && \
44-
yum clean all
25+
dnf clean all
4526

4627
###############################################################################
4728
# Google Cloud SDK
@@ -66,6 +47,10 @@ RUN groupadd -g 1100 aougroup && \
6647
###############################################################################
6748
RUN echo "-work /data/saswork" >> /opt/sas/viya/config/etc/workspaceserver/default/sasv9_usermods.cfg && \
6849
echo "-utilloc /data/utilloc" >> /opt/sas/viya/config/etc/workspaceserver/default/sasv9_usermods.cfg && \
50+
echo 'if [ -f /data/.aou-env ]; then source /data/.aou-env; fi' >> \
51+
/opt/sas/viya/config/etc/workspaceserver/default/workspaceserver_usermods.sh && \
52+
echo 'if [ -f /data/.workbench-env ]; then source /data/.workbench-env; fi' >> \
53+
/opt/sas/viya/config/etc/workspaceserver/default/workspaceserver_usermods.sh && \
6954
sed -Ei 's#^USERMODS=(.*)#USERMODS=-allowxcmd \1#g' \
7055
/opt/sas/viya/config/etc/spawner/default/spawner_usermods.sh
7156

@@ -87,6 +72,12 @@ RUN PROXY_CONF=/etc/httpd/conf.d/dkrapro-proxy.conf && \
8772
sed -i '/AOU-CONFIGURED/a Header unset Content-Security-Policy' "${PROXY_CONF}" && \
8873
sed -i '/AOU-CONFIGURED/a Header edit Set-Cookie "^(.*SameSite=None.*)\$" "\$1; Secure"' "${PROXY_CONF}"
8974

75+
###############################################################################
76+
# Create /data directory and chown to AoU user. When the volume is mounted it
77+
# will inherit the owner
78+
###############################################################################
79+
RUN mkdir -p /data && chown aou:aougroup /data
80+
9081
# Wrapper entrypoint: copies the SAS license from Mikey Secrets (if active)
9182
# to /sasinside/ before handing off to the SAS entrypoint.
9283
COPY --from=wb-secret-receiver /dist/wb-secret-receiver /wb-secret-receiver
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"id": "aou-sas",
3+
"version": "1.0.0",
4+
"name": "SAS App for AoU",
5+
"description": "SAS Analytics Pro for All of Us",
6+
"options": {
7+
"cloud": {
8+
"type": "string",
9+
"description": "VM cloud environment",
10+
"proposals": ["gcp", "aws"],
11+
"default": "gcp"
12+
},
13+
"login": {
14+
"type": "string",
15+
"description": "Whether to log in to workbench CLI",
16+
"proposals": ["true", "false"],
17+
"default": "false"
18+
}
19+
}
20+
}

src/aou-sas/docker-compose.yaml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,17 @@ services:
1818
# SAS startup script — invoked via PRE_DEPLOY_SCRIPT before SAS
1919
# services start. Must NOT mount at /tmp/pre_deploy.sh because
2020
# the entrypoint overwrites that path with the env var content.
21-
- ./sas-startup.sh:/opt/sas/aou/sas-startup.sh:ro
22-
# Fallback license mount for manual GCE testing without Mikey Secrets.
23-
# With Mikey Secrets, the entrypoint wrapper populates /sasinside/ from
24-
# the SAS_LICENSE_PATH file descriptor instead.
25-
- ./sasinside:/sasinside
21+
- ./sas-pre-deploy.sh:/opt/sas/aou/sas-pre-deploy.sh:ro
22+
- ./sas-post-deploy.sh:/opt/sas/aou/sas-post-deploy.sh:ro
2623
tmpfs:
2724
- /data/workspace:uid=1002,gid=1100
2825
environment:
2926
HOST_AUTH: ""
3027
SAS_DEBUG: "0"
3128
SASLICENSEFILE: "SASLicense.jwt"
3229
GOMEMLIMIT: "20MiB"
33-
PRE_DEPLOY_SCRIPT: "bash /opt/sas/aou/sas-startup.sh"
30+
PRE_DEPLOY_SCRIPT: "bash /opt/sas/aou/sas-pre-deploy.sh"
31+
POST_DEPLOY_SCRIPT: "bash /opt/sas/aou/sas-post-deploy.sh"
3432
JAVA_OPTION_SAS_COMMONS_WEB_SECURITY_CORS_ALLOWEDORIGINS: "-Dsas.commons.web.security.cors.allowedOrigins=*"
3533
JAVA_OPTION_SAS_COMMONS_WEB_SECURITY_CORS_ALLOWCREDENTIALS: "-Dsas.commons.web.security.cors.allowCredentials=false"
3634
JAVA_OPTION_SAS_COMMONS_WEB_SECURITY_CORS_ALLOWEDHEADERS: "-Dsas.commons.web.security.cors.allowedHeaders=*"

src/aou-sas/sas-entrypoint.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66
# copies the license to /sasinside/SASLicense.jwt where the SAS Analytics
77
# Pro entrypoint expects it.
88
#
9-
# When SAS_LICENSE_PATH is not set (manual GCE testing), this script is a
10-
# no-op passthrough — SAS reads the license from the bind-mounted /sasinside/.
9+
# When SAS_LICENSE_PATH is not set, this script is a no-op passthrough.
1110

1211
if [ -n "${SAS_LICENSE_PATH:-}" ]; then
1312
mkdir -p /sasinside
1413
cp "$SAS_LICENSE_PATH" /sasinside/SASLicense.jwt
1514
chmod 400 /sasinside/SASLicense.jwt
16-
chown root:root /sasinside/SASLicense.jwt
15+
chown sas:sas /sasinside/SASLicense.jwt
1716
fi
1817

1918
exec /opt/sas/viya/home/bin/sas-analytics-pro-entrypoint.sh "$@"

src/aou-sas/sas-post-deploy.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
# sas-post-deploy.sh — Lock down the SAS license after it has been applied.
3+
#
4+
# Invoked via POST_DEPLOY_SCRIPT after SAS services start. The license must
5+
# be readable by the sas user during application (PRE_DEPLOY), but afterward
6+
# we restrict it to root so the aou user cannot exfiltrate it via pipe commands.
7+
8+
set -o errexit
9+
set -o nounset
10+
set -o pipefail
11+
12+
if [ -f /sasinside/SASLicense.jwt ]; then
13+
chmod 400 /sasinside/SASLicense.jwt
14+
chown root:root /sasinside/SASLicense.jwt
15+
fi
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
2-
# sas-startup.sh — Runtime setup for SAS Analytics Pro on VWB GCE.
2+
# sas-pre-deploy.sh — Runtime setup for SAS Analytics Pro on VWB GCE.
33
#
4-
# Mounted at /opt/sas/aou/sas-startup.sh and invoked via PRE_DEPLOY_SCRIPT
4+
# Mounted at /opt/sas/aou/sas-pre-deploy.sh and invoked via PRE_DEPLOY_SCRIPT
55
# before SAS services start. Only handles steps that depend on the /data
66
# volume or runtime state; build-time setup is in the Dockerfile.
77
#
@@ -17,22 +17,10 @@ set -o pipefail
1717
mkdir -p /data/saswork /data/utilloc
1818
chown -R aou:aougroup /data
1919

20-
###############################################################################
21-
# Lock down the SAS license so the aou user cannot read it via pipe commands.
22-
# The entrypoint wrapper already sets root:root 0400 for Mikey Secrets, but
23-
# this covers the bind-mount fallback and acts as defence in depth.
24-
###############################################################################
25-
if [ -f /sasinside/SASLicense.jwt ]; then
26-
chown root:root /sasinside/SASLicense.jwt
27-
chmod 400 /sasinside/SASLicense.jwt
28-
fi
29-
3020
###############################################################################
3121
# AoU environment loader (staged in Dockerfile at /opt/sas/aou/)
3222
###############################################################################
3323
if [ -d /opt/sas/aou ]; then
3424
cp -n /opt/sas/aou/load-env /opt/sas/aou/load-env.sh /data/ 2>/dev/null || true
3525
chown aou:aougroup /data/load-env /data/load-env.sh 2>/dev/null || true
36-
grep -q "load-env.sh" /data/.bashrc 2>/dev/null || \
37-
echo "source /data/load-env.sh" >> /data/.bashrc
3826
fi

src/aou-sas/sasinside/.gitignore

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/aou-sas/secrets.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ secrets:
22
- name: "SASDockerAuth"
33
dockerRegistry: "cr.sas.com"
44
- name: "SASLicense"
5-
pathVar: "SAS_LICENSE_PATH"
5+
pipeVar: "SAS_LICENSE_PATH"

src/aou-sas/setup-sas-env.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
# setup-sas-env.sh — Populate environment files for SAS Studio sessions.
3+
#
4+
# Runs after post-startup.sh (or remount-on-restart.sh) to create env files
5+
# that the SAS workspace server sources on session start.
6+
#
7+
# - /data/.aou-env: AoU CDR variables (from load-env)
8+
# - /data/.workbench-env: Workbench variables (extracted from .bashrc)
9+
10+
set -o errexit
11+
set -o nounset
12+
set -o pipefail
13+
14+
readonly USER_NAME="${1}"
15+
readonly DATA_DIR="${2}"
16+
17+
if [ -f "${DATA_DIR}/load-env.sh" ]; then
18+
sudo -u "${USER_NAME}" bash -c "source '${DATA_DIR}/load-env.sh'" || true
19+
fi
20+
21+
# Extract export statements from .bashrc to get workbench environment variables
22+
grep '^export ' "${DATA_DIR}/.bashrc" > "${DATA_DIR}/.workbench-env" || true

0 commit comments

Comments
 (0)