Skip to content

Commit 68fa6d1

Browse files
authored
fix(codespaces): fix reverse proxy warning and enable CSP (#2184)
Jenkins showed "reverse proxy set up is broken" in Codespaces because codespacesURL.sh only edits the host-side jenkins.yaml, which is never read at runtime — the baked-in image copy is used instead. The discovery container (find-name.sh) already modifies /var/jenkins_home/jenkins.yaml and triggers a JCasc reload, so it is the right place to also set the correct root URL. Changes: - docker-compose.yaml: pass CODESPACE_NAME and GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN into the discovery container - find-name.sh: when those vars are present, update unclassified.location.url to the Codespaces forwarding URL and suppress the ReverseProxySetupMonitor admin warning - jenkins.yaml: add security.contentSecurityPolicy with a permissive but defined policy to clear the CSP administrative monitor warning Signed-off-by: Bruno Verachten <gounthar@gmail.com>
1 parent a9d8286 commit 68fa6d1

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

docker-compose.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ services:
3030
stdin_open: true
3131
tty: true
3232
entrypoint: sh -c "/usr/local/bin/find-name.sh"
33+
environment:
34+
- CODESPACE_NAME=${CODESPACE_NAME:-}
35+
- GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN=${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN:-}
3336
profiles:
3437
- maven
3538
- python

dockerfiles/agent-discovery/find-name.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ cat /var/jenkins_home/jenkins.yaml
3131
# Hopefully, Jenkins will load this JCasc configuration after we change the value
3232
# We will modify this file later on with the name of the agent machine, but this change has to happen as soon as possible, so Jenkins knows the token to reload the configuration later on, once we have found the agent machine name.
3333

34+
# If running in GitHub Codespaces, update the Jenkins root URL so the reverse proxy check passes
35+
if [ -n "${CODESPACE_NAME:-}" ] && [ -n "${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN:-}" ]; then
36+
JENKINS_URL="https://${CODESPACE_NAME}-8080.${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}/"
37+
export JENKINS_URL
38+
yq eval -i '.unclassified.location.url = env(JENKINS_URL)' /var/jenkins_home/jenkins.yaml
39+
yq eval -i '(.jenkins.disabledAdministrativeMonitors // []) as $m | .jenkins.disabledAdministrativeMonitors = ($m + ["hudson.diagnosis.ReverseProxySetupMonitor"] | unique)' /var/jenkins_home/jenkins.yaml
40+
echo "✅ Codespaces detected — Jenkins URL set to: ${JENKINS_URL}"
41+
fi
42+
3443
# Get the IP address of the host machine
3544
# The hostname -I command is used to print all network addresses of the host.
3645
# The awk command is used to print the first field (the first IP address).

dockerfiles/jenkins.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ credentials:
4040
privateKey: ${readFile:/ssh-dir/jenkins_agent_ed}
4141
scope: SYSTEM
4242
username: "jenkins"
43+
security:
44+
contentSecurityPolicy:
45+
header: >-
46+
sandbox allow-same-origin allow-scripts allow-popups allow-forms;
47+
default-src 'self';
48+
img-src 'self' data:;
49+
style-src 'self' 'unsafe-inline';
50+
script-src 'self' 'unsafe-inline';
51+
font-src 'self';
4352
unclassified:
4453
location:
4554
url: "http://127.0.0.1:8080/"

0 commit comments

Comments
 (0)