Skip to content

Commit fc4df6d

Browse files
Copilotcoopernetes
andcommitted
Address code review feedback: use git-proxy.yml, add env vars, remove GitHub auth filter, use info log
- Changed config files from application.yml/application-local.yml to git-proxy.yml/git-proxy-local.yml for Jetty separation from Spring - Added environment variable override support with GITPROXY_ prefix (GITPROXY_SERVER_PORT, GITPROXY_GITPROXY_BASEPATH) - Removed GitHubUserAuthenticatedFilter entirely (GitHub enforces auth itself, proxy forwards errors transparently) - Changed disabled provider log level from debug to info for better visibility - Updated CONFIGURATION.md to document new file names and environment variable support - Removed GitHub authentication filter from config examples Co-authored-by: coopernetes <57812123+coopernetes@users.noreply.github.com>
1 parent 1edf2ba commit fc4df6d

6 files changed

Lines changed: 176 additions & 106 deletions

File tree

CONFIGURATION.md

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
# Configuration Guide
22

3-
The Jetty-based GitProxy server supports configuration via YAML files. This allows you to configure providers, filters, and other server settings without modifying code.
3+
The Jetty-based GitProxy server supports configuration via YAML files and environment variables. This allows you to configure providers, filters, and other server settings without modifying code.
44

55
## Configuration Files
66

77
The server loads configuration from the following files in order:
8-
1. `src/main/resources/application.yml` - Base configuration
9-
2. `src/main/resources/application-local.yml` - Local overrides (merged with base)
8+
1. `src/main/resources/git-proxy.yml` - Base configuration
9+
2. `src/main/resources/git-proxy-local.yml` - Local overrides (merged with base)
10+
3. Environment variables with `GITPROXY_` prefix
1011

11-
Configuration from `application-local.yml` will override or extend settings from `application.yml`.
12+
Configuration from `git-proxy-local.yml` will override or extend settings from `git-proxy.yml`, and environment variables will override both.
13+
14+
## Environment Variable Overrides
15+
16+
You can override certain configuration values using environment variables with the `GITPROXY_` prefix:
17+
18+
- `GITPROXY_SERVER_PORT`: Override the server port (e.g., `GITPROXY_SERVER_PORT=9090`)
19+
- `GITPROXY_GITPROXY_BASEPATH`: Override the base path (e.g., `GITPROXY_GITPROXY_BASEPATH=/proxy`)
20+
21+
Note: Whitelist configurations are not supported via environment variables due to their complex structure.
1222

1323
## Server Configuration
1424

@@ -61,29 +71,7 @@ git-proxy:
6171

6272
Filters control access to repositories and enforce policies.
6373

64-
### GitHub User Authentication Filter
65-
66-
Requires authentication for GitHub operations.
67-
68-
```yaml
69-
git-proxy:
70-
filters:
71-
github-user-authenticated:
72-
enabled: true
73-
order: 1
74-
operations:
75-
- PUSH
76-
required-auth-schemes: bearer, token, basic # Can be comma-separated or list
77-
providers:
78-
- github
79-
```
80-
81-
Options:
82-
- `enabled` (boolean): Enable/disable the filter
83-
- `order` (int): Filter execution order (lower numbers run first)
84-
- `operations` (list): Git operations to apply filter to (PUSH, FETCH)
85-
- `required-auth-schemes` (string or list): Required authentication schemes (bearer, token, basic)
86-
- `providers` (list): Provider names to apply filter to
74+
Note: GitHub already enforces authentication for push operations using personal access tokens (PATs). The proxy transparently forwards requests upstream and returns errors from GitHub directly, so authentication checking is handled by GitHub itself.
8775

8876
### Whitelist Filters
8977

src/main/java/org/finos/gitproxy/config/JettyConfigurationBuilder.java

Lines changed: 1 addition & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.net.URI;
44
import java.util.*;
55
import lombok.extern.slf4j.Slf4j;
6-
import org.finos.gitproxy.git.HttpAuthScheme;
76
import org.finos.gitproxy.git.HttpOperation;
87
import org.finos.gitproxy.provider.*;
98
import org.finos.gitproxy.servlet.filter.*;
@@ -41,7 +40,7 @@ public List<GitProxyProvider> buildProviders() {
4140

4241
boolean enabled = (Boolean) providerConfig.getOrDefault("enabled", false);
4342
if (!enabled) {
44-
log.debug("Provider {} is disabled, skipping", providerName);
43+
log.info("Provider {} is disabled, skipping", providerName);
4544
continue;
4645
}
4746

@@ -108,9 +107,6 @@ public List<GitProxyFilter> buildFiltersForProvider(GitProxyProvider provider) {
108107
filters.add(new ForceGitClientFilter());
109108
filters.add(new ParseGitRequestFilter(provider));
110109

111-
// Build GitHub user authenticated filter
112-
filters.addAll(buildGitHubUserAuthFilter(provider, filtersConfig));
113-
114110
// Build whitelist filters
115111
filters.addAll(buildWhitelistFilters(provider, filtersConfig));
116112

@@ -121,74 +117,6 @@ public List<GitProxyFilter> buildFiltersForProvider(GitProxyProvider provider) {
121117
return filters;
122118
}
123119

124-
/** Build GitHub user authentication filter if configured. */
125-
@SuppressWarnings("unchecked")
126-
private List<GitProxyFilter> buildGitHubUserAuthFilter(
127-
GitProxyProvider provider, Map<String, Object> filtersConfig) {
128-
List<GitProxyFilter> filters = new ArrayList<>();
129-
130-
if (!(provider instanceof GitHubProvider)) {
131-
return filters;
132-
}
133-
134-
Object githubUserAuthConfig = filtersConfig.get("github-user-authenticated");
135-
if (githubUserAuthConfig == null) {
136-
return filters;
137-
}
138-
139-
Map<String, Object> authConfig = (Map<String, Object>) githubUserAuthConfig;
140-
boolean enabled = (Boolean) authConfig.getOrDefault("enabled", false);
141-
if (!enabled) {
142-
return filters;
143-
}
144-
145-
// Check if this provider is in the list
146-
List<String> providerList = (List<String>) authConfig.get("providers");
147-
if (providerList != null && !providerList.contains(provider.getName())) {
148-
return filters;
149-
}
150-
151-
int order = (Integer) authConfig.getOrDefault("order", 1);
152-
Object authSchemesObj = authConfig.get("required-auth-schemes");
153-
154-
Set<HttpAuthScheme> schemes = new HashSet<>();
155-
if (authSchemesObj != null) {
156-
List<String> authSchemes;
157-
if (authSchemesObj instanceof List) {
158-
authSchemes = (List<String>) authSchemesObj;
159-
} else if (authSchemesObj instanceof String) {
160-
// Handle comma-separated string
161-
String authSchemesStr = (String) authSchemesObj;
162-
authSchemes = Arrays.asList(authSchemesStr.split("\\s*,\\s*"));
163-
} else {
164-
authSchemes = new ArrayList<>();
165-
}
166-
167-
for (String scheme : authSchemes) {
168-
switch (scheme.toLowerCase().trim()) {
169-
case "basic":
170-
schemes.add(HttpAuthScheme.BASIC);
171-
break;
172-
case "bearer":
173-
schemes.add(HttpAuthScheme.BEARER);
174-
break;
175-
case "token":
176-
schemes.add(HttpAuthScheme.TOKEN);
177-
break;
178-
}
179-
}
180-
} else {
181-
schemes.add(HttpAuthScheme.BEARER);
182-
}
183-
184-
GitHubUserAuthenticatedFilter filter =
185-
new GitHubUserAuthenticatedFilter(order, (GitHubProvider) provider, schemes);
186-
filters.add(filter);
187-
log.info("Created GitHubUserAuthenticatedFilter for provider: {}", provider.getName());
188-
189-
return filters;
190-
}
191-
192120
/** Build whitelist filters if configured. */
193121
@SuppressWarnings("unchecked")
194122
private List<GitProxyFilter> buildWhitelistFilters(GitProxyProvider provider, Map<String, Object> filtersConfig) {

src/main/java/org/finos/gitproxy/config/JettyConfigurationLoader.java

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@
88

99
/**
1010
* Configuration loader for the Jetty-based GitProxy application. This class reads configuration from YAML files
11-
* (application.yml, application-local.yml) and provides a structured representation of the configuration that can be
12-
* used to bootstrap the Jetty server with appropriate providers and filters.
11+
* (git-proxy.yml, git-proxy-local.yml) and environment variables, providing a structured representation of the
12+
* configuration that can be used to bootstrap the Jetty server with appropriate providers and filters.
13+
*
14+
* <p>Environment variables with the prefix GITPROXY_ can override configuration values. For example: -
15+
* GITPROXY_SERVER_PORT=9090 overrides server.port - GITPROXY_GITPROXY_BASEPATH=/proxy overrides git-proxy.base-path
1316
*/
1417
@Slf4j
1518
public class JettyConfigurationLoader {
1619

17-
private static final String DEFAULT_CONFIG = "application.yml";
18-
private static final String LOCAL_CONFIG = "application-local.yml";
20+
private static final String DEFAULT_CONFIG = "git-proxy.yml";
21+
private static final String LOCAL_CONFIG = "git-proxy-local.yml";
22+
private static final String ENV_PREFIX = "GITPROXY_";
1923

2024
private Map<String, Object> config;
2125

@@ -24,8 +28,8 @@ public JettyConfigurationLoader() {
2428
}
2529

2630
/**
27-
* Load configuration from YAML files. Loads application.yml first, then overlays application-local.yml if it
28-
* exists.
31+
* Load configuration from YAML files and environment variables. Loads git-proxy.yml first, then overlays
32+
* git-proxy-local.yml if it exists, and finally applies environment variable overrides.
2933
*/
3034
private Map<String, Object> loadConfiguration() {
3135
Yaml yaml = new Yaml();
@@ -39,6 +43,8 @@ private Map<String, Object> loadConfiguration() {
3943
baseConfig = loaded;
4044
log.info("Loaded base configuration from {}", DEFAULT_CONFIG);
4145
}
46+
} else {
47+
log.warn("Base configuration file {} not found, using defaults", DEFAULT_CONFIG);
4248
}
4349
} catch (IOException e) {
4450
log.warn("Failed to load base configuration from {}: {}", DEFAULT_CONFIG, e.getMessage());
@@ -52,11 +58,16 @@ private Map<String, Object> loadConfiguration() {
5258
deepMerge(baseConfig, localConfig);
5359
log.info("Loaded and merged local configuration from {}", LOCAL_CONFIG);
5460
}
61+
} else {
62+
log.debug("Local configuration file {} not found, skipping", LOCAL_CONFIG);
5563
}
5664
} catch (IOException e) {
5765
log.debug("No local configuration found at {}", LOCAL_CONFIG);
5866
}
5967

68+
// Apply environment variable overrides
69+
applyEnvironmentOverrides(baseConfig);
70+
6071
return baseConfig;
6172
}
6273

@@ -80,6 +91,44 @@ private void deepMerge(Map<String, Object> base, Map<String, Object> overlay) {
8091
}
8192
}
8293

94+
/**
95+
* Apply environment variable overrides to configuration. Supported environment variables: - GITPROXY_SERVER_PORT:
96+
* Override server port - GITPROXY_GITPROXY_BASEPATH: Override git-proxy base path
97+
*/
98+
@SuppressWarnings("unchecked")
99+
private void applyEnvironmentOverrides(Map<String, Object> config) {
100+
Map<String, String> env = System.getenv();
101+
102+
// Override server port
103+
String portEnv = env.get(ENV_PREFIX + "SERVER_PORT");
104+
if (portEnv != null) {
105+
try {
106+
int port = Integer.parseInt(portEnv);
107+
Map<String, Object> serverConfig =
108+
(Map<String, Object>) config.computeIfAbsent("server", k -> new HashMap<>());
109+
serverConfig.put("port", port);
110+
log.info("Overriding server port from environment: {}", port);
111+
} catch (NumberFormatException e) {
112+
log.warn("Invalid port value in GITPROXY_SERVER_PORT: {}", portEnv);
113+
}
114+
}
115+
116+
// Override base path
117+
String basePathEnv = env.get(ENV_PREFIX + "GITPROXY_BASEPATH");
118+
if (basePathEnv != null) {
119+
Map<String, Object> gitProxyConfig =
120+
(Map<String, Object>) config.computeIfAbsent("git-proxy", k -> new HashMap<>());
121+
gitProxyConfig.put("base-path", basePathEnv);
122+
log.info("Overriding base path from environment: {}", basePathEnv);
123+
}
124+
125+
// Log other GITPROXY_ variables for visibility
126+
env.keySet().stream()
127+
.filter(k -> k.startsWith(ENV_PREFIX))
128+
.filter(k -> !k.equals(ENV_PREFIX + "SERVER_PORT") && !k.equals(ENV_PREFIX + "GITPROXY_BASEPATH"))
129+
.forEach(k -> log.debug("Found environment variable {} (not currently supported)", k));
130+
}
131+
83132
/** Get the git-proxy configuration section. */
84133
@SuppressWarnings("unchecked")
85134
public Map<String, Object> getGitProxyConfig() {
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
management:
2+
endpoints:
3+
web:
4+
exposure:
5+
include: "*"
6+
logging:
7+
level:
8+
org.finos.gitproxy: DEBUG
9+
org.finos.gitproxy.git: DEBUG
10+
# org.eclipse.jgit.transport: DEBUG
11+
git-proxy:
12+
filters:
13+
whitelists:
14+
- enabled: true
15+
order: 5
16+
operations:
17+
- FETCH
18+
- PUSH
19+
providers:
20+
- gitlab
21+
slugs:
22+
- coopernetes/test-repo
23+
owners:
24+
- finosfoundation
25+
names:
26+
- hello-world
27+
- enabled: true
28+
order: 10
29+
operations:
30+
- PUSH
31+
owners:
32+
- finosfoundation
33+
providers:
34+
- gitlab
35+
- enabled: true
36+
order: 10
37+
operations:
38+
- PUSH
39+
slugs:
40+
- finos/git-proxy
41+
providers:
42+
- github
43+
- enabled: true
44+
order: 20
45+
operations:
46+
- FETCH
47+
owners:
48+
- finos
49+
providers:
50+
- github
51+
- enabled: true
52+
order: 30
53+
operations:
54+
- FETCH
55+
- PUSH
56+
slugs:
57+
- coopernetes/test-repo
58+
- coopernetes/test-repo2
59+
providers:
60+
- github

src/main/resources/git-proxy.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
spring:
2+
application:
3+
name: jgit-proxy
4+
server:
5+
port: 8080
6+
management:
7+
endpoints:
8+
web:
9+
exposure:
10+
include: mappings, health, info
11+
logging:
12+
level:
13+
org.finos.gitproxy: INFO
14+
# The below is a minimal configuration needed for the app to start and is the default shipped with the jar.
15+
# By default, the app supports proxying to GitHub, GitLab, and Bitbucket. Users should override this configuration
16+
# to suit their needs.
17+
git-proxy:
18+
# base-path: "/git"
19+
providers:
20+
github:
21+
enabled: true
22+
gitlab:
23+
enabled: true
24+
bitbucket:
25+
enabled: true
26+
# internal-github:
27+
# enabled: true
28+
# servlet-path: /enterprise-github
29+
# uri: https://githubserver.example.com
30+
# internal-gitlab:
31+
# enabled: true
32+
# servlet-path: /external-github
33+
# uri: https://gitlabserver.other.example.com
34+
debian-gitlab:
35+
enabled: true
36+
servlet-path: /debian
37+
uri: https://salsa.debian.org/

src/test/resources/git-proxy.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
git-proxy:
2+
providers:
3+
github:
4+
enabled: true
5+
logging:
6+
level:
7+
com.fasterxml.jackson: TRACE
8+
org.springframework.boot.context.config: TRACE

0 commit comments

Comments
 (0)