Skip to content

Commit ac1c42d

Browse files
authored
fix(codespaces): fix reverse proxy warning and enable CSP (#2185)
Backport of the main branch fix. Same three changes: - docker-compose.yaml: pass CODESPACE_NAME and GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN into the discovery container - find-name.sh: update unclassified.location.url and suppress ReverseProxySetupMonitor when running in Codespaces - jenkins.yaml: add security.contentSecurityPolicy to clear the CSP administrative monitor warning Signed-off-by: Bruno Verachten <gounthar@gmail.com>
1 parent 2dcfca7 commit ac1c42d

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
@@ -28,6 +28,9 @@ services:
2828
stdin_open: true
2929
tty: true
3030
entrypoint: sh -c "/usr/local/bin/find-name.sh"
31+
environment:
32+
- CODESPACE_NAME=${CODESPACE_NAME:-}
33+
- GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN=${GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN:-}
3134
profiles:
3235
- maven
3336
- 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
@@ -39,6 +39,15 @@ credentials:
3939
privateKey: ${readFile:/ssh-dir/jenkins_agent_ed}
4040
scope: SYSTEM
4141
username: "jenkins"
42+
security:
43+
contentSecurityPolicy:
44+
header: >-
45+
sandbox allow-same-origin allow-scripts allow-popups allow-forms;
46+
default-src 'self';
47+
img-src 'self' data:;
48+
style-src 'self' 'unsafe-inline';
49+
script-src 'self' 'unsafe-inline';
50+
font-src 'self';
4251
unclassified:
4352
location:
4453
url: "http://127.0.0.1:8080/"

0 commit comments

Comments
 (0)