Skip to content

Commit 2fedac7

Browse files
th-2021kkimurak
authored andcommitted
configure NGINX for GITLAB_BUILTIN_KAS
Add kas location to assets/runtime/config/nginx/gitlab(-ssl) config KAS location is affected by GITLAB_RELATIVE_URL_ROOT so add update process to assets/runtime/functions
1 parent 94ca2e7 commit 2fedac7

3 files changed

Lines changed: 103 additions & 0 deletions

File tree

assets/runtime/config/nginx/gitlab

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,54 @@ server {
8484
proxy_pass http://gitlab-workhorse;
8585
}
8686

87+
#start-builtin-kas
88+
location {{GITLAB_RELATIVE_URL_ROOT}}/-/kubernetes-agent/ {
89+
client_max_body_size 0;
90+
gzip off;
91+
92+
## https://github.com/gitlabhq/gitlabhq/issues/694
93+
## Some requests take more than 30 seconds.
94+
proxy_read_timeout 300;
95+
proxy_connect_timeout 300;
96+
proxy_redirect off;
97+
proxy_buffering {{NGINX_PROXY_BUFFERING}};
98+
99+
proxy_http_version 1.1;
100+
101+
proxy_set_header Host $http_host;
102+
proxy_set_header X-Real-IP $remote_addr;
103+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
104+
proxy_set_header X-Forwarded-Proto {{NGINX_X_FORWARDED_PROTO}};
105+
proxy_set_header Upgrade $http_upgrade;
106+
proxy_set_header Connection $connection_upgrade_gitlab;
107+
108+
proxy_pass http://127.0.0.1:8150;
109+
}
110+
111+
location {{GITLAB_RELATIVE_URL_ROOT}}/-/kubernetes-agent/k8s-proxy/ {
112+
client_max_body_size 0;
113+
gzip off;
114+
115+
## https://github.com/gitlabhq/gitlabhq/issues/694
116+
## Some requests take more than 30 seconds.
117+
proxy_read_timeout 300;
118+
proxy_connect_timeout 300;
119+
proxy_redirect off;
120+
proxy_buffering {{NGINX_PROXY_BUFFERING}};
121+
122+
proxy_http_version 1.1;
123+
124+
proxy_set_header Host $http_host;
125+
proxy_set_header X-Real-IP $remote_addr;
126+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
127+
proxy_set_header X-Forwarded-Proto {{NGINX_X_FORWARDED_PROTO}};
128+
proxy_set_header Upgrade $http_upgrade;
129+
proxy_set_header Connection $connection_upgrade_gitlab;
130+
131+
proxy_pass http://127.0.0.1:8154;
132+
}
133+
#end-builtin-kas
134+
87135
error_page 404 /404.html;
88136
error_page 422 /422.html;
89137
error_page 500 /500.html;

assets/runtime/config/nginx/gitlab-ssl

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,54 @@ server {
131131
proxy_pass http://gitlab-workhorse;
132132
}
133133

134+
#start-builtin-kas
135+
location {{GITLAB_RELATIVE_URL_ROOT}}/-/kubernetes-agent/ {
136+
client_max_body_size 0;
137+
gzip off;
138+
139+
## https://github.com/gitlabhq/gitlabhq/issues/694
140+
## Some requests take more than 30 seconds.
141+
proxy_read_timeout 300;
142+
proxy_connect_timeout 300;
143+
proxy_redirect off;
144+
proxy_buffering {{NGINX_PROXY_BUFFERING}};
145+
146+
proxy_http_version 1.1;
147+
148+
proxy_set_header Host $http_host;
149+
proxy_set_header X-Real-IP $remote_addr;
150+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
151+
proxy_set_header X-Forwarded-Proto {{NGINX_X_FORWARDED_PROTO}};
152+
proxy_set_header Upgrade $http_upgrade;
153+
proxy_set_header Connection $connection_upgrade_gitlab;
154+
155+
proxy_pass http://127.0.0.1:8150;
156+
}
157+
158+
location {{GITLAB_RELATIVE_URL_ROOT}}/-/kubernetes-agent/k8s-proxy/ {
159+
client_max_body_size 0;
160+
gzip off;
161+
162+
## https://github.com/gitlabhq/gitlabhq/issues/694
163+
## Some requests take more than 30 seconds.
164+
proxy_read_timeout 300;
165+
proxy_connect_timeout 300;
166+
proxy_redirect off;
167+
proxy_buffering {{NGINX_PROXY_BUFFERING}};
168+
169+
proxy_http_version 1.1;
170+
171+
proxy_set_header Host $http_host;
172+
proxy_set_header X-Real-IP $remote_addr;
173+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
174+
proxy_set_header X-Forwarded-Proto {{NGINX_X_FORWARDED_PROTO}};
175+
proxy_set_header Upgrade $http_upgrade;
176+
proxy_set_header Connection $connection_upgrade_gitlab;
177+
178+
proxy_pass http://127.0.0.1:8154;
179+
}
180+
#end-builtin-kas
181+
134182
error_page 404 /404.html;
135183
error_page 422 /422.html;
136184
error_page 500 /500.html;

assets/runtime/functions

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,12 +1599,19 @@ nginx_configure_gitlab_real_ip() {
15991599

16001600
nginx_configure_gitlab() {
16011601
echo "Configuring nginx::gitlab..."
1602+
if [[ ! ${GITLAB_AGENT_BUILTIN_KAS_ENABLED} == true ]]; then
1603+
sed -i "/#start-builtin-kas/,/#end-builtin-kas/d" ${GITLAB_NGINX_CONFIG}
1604+
else
1605+
sed -i "/#start-builtin-kas/d" ${GITLAB_NGINX_CONFIG}
1606+
sed -i "/#end-builtin-kas/d" ${GITLAB_NGINX_CONFIG}
1607+
fi
16021608
update_template ${GITLAB_NGINX_CONFIG} \
16031609
GITLAB_HOME \
16041610
GITLAB_INSTALL_DIR \
16051611
GITLAB_LOG_DIR \
16061612
GITLAB_HOST \
16071613
GITLAB_PORT \
1614+
GITLAB_RELATIVE_URL_ROOT \
16081615
NGINX_PROXY_BUFFERING \
16091616
NGINX_ACCEL_BUFFERING \
16101617
NGINX_X_FORWARDED_PROTO \

0 commit comments

Comments
 (0)