Hithomelabs/CFTunnels#122: Add trust-all SSL RestTemplate for prod profile
All checks were successful
Daily cloudflare API integration test / cloudflare-api-test (push) Successful in 1m50s
sample gradle build and test / build (pull_request) Successful in 1m58s
Build & Push Portainer Automation / version (push) Successful in 7s
Build & Push Portainer Automation / build-and-push (push) Successful in 2m6s
Build & Push CFTunnels / version (push) Successful in 7s
Build & Push CFTunnels / build-and-push (push) Successful in 2m24s
All checks were successful
Daily cloudflare API integration test / cloudflare-api-test (push) Successful in 1m50s
sample gradle build and test / build (pull_request) Successful in 1m58s
Build & Push Portainer Automation / version (push) Successful in 7s
Build & Push Portainer Automation / build-and-push (push) Successful in 2m6s
Build & Push CFTunnels / version (push) Successful in 7s
Build & Push CFTunnels / build-and-push (push) Successful in 2m24s
Extract trust-all SSL logic into buildTrustAllRestTemplate() helper.
Add @Profile("prod") bean that also trusts self-signed certs.
Change @Profile("!local") to @Profile("!local & !prod") so standard
strict SSL is only used for CI/test profiles.
Rename portainerRestTemplate() to portainerRestTemplateDefault().
This commit is contained in:
parent
3bffa43d6a
commit
52f40e3d92
@ -22,12 +22,11 @@ import java.security.cert.X509Certificate;
|
||||
public class PortainerClientConfig {
|
||||
|
||||
/**
|
||||
* Trust-all SSL RestTemplate for the "local" profile.
|
||||
* Used when connecting via Cloudflare Tunnel (self-signed certs).
|
||||
* Builds a RestTemplate that trusts all SSL certificates.
|
||||
* Used when connecting via Cloudflare Tunnel (self-signed certs)
|
||||
* or to the prod Portainer instance (also self-signed).
|
||||
*/
|
||||
@Profile("local")
|
||||
@Bean(name = "portainerRestTemplate")
|
||||
public RestTemplate portainerRestTemplateLocal() throws Exception {
|
||||
private static RestTemplate buildTrustAllRestTemplate() throws Exception {
|
||||
TrustManager[] trustAllCerts = new TrustManager[]{
|
||||
new X509TrustManager() {
|
||||
public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; }
|
||||
@ -47,12 +46,32 @@ public class PortainerClientConfig {
|
||||
}
|
||||
|
||||
/**
|
||||
* Standard validating SSL RestTemplate for non-local profiles
|
||||
* (CI, test, prod — internal Docker network).
|
||||
* Trust-all SSL RestTemplate for the "local" profile.
|
||||
* Used when connecting via Cloudflare Tunnel (self-signed certs).
|
||||
*/
|
||||
@Profile("!local")
|
||||
@Profile("local")
|
||||
@Bean(name = "portainerRestTemplate")
|
||||
public RestTemplate portainerRestTemplate() {
|
||||
public RestTemplate portainerRestTemplateLocal() throws Exception {
|
||||
return buildTrustAllRestTemplate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Trust-all SSL RestTemplate for the "prod" profile.
|
||||
* Prod Portainer at https://192.168.0.100:9443 uses a self-signed certificate.
|
||||
*/
|
||||
@Profile("prod")
|
||||
@Bean(name = "portainerRestTemplate")
|
||||
public RestTemplate portainerRestTemplateProd() throws Exception {
|
||||
return buildTrustAllRestTemplate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Standard validating SSL RestTemplate for profiles other than local and prod
|
||||
* (CI, test — internal Docker network with valid certs).
|
||||
*/
|
||||
@Profile("!local & !prod")
|
||||
@Bean(name = "portainerRestTemplate")
|
||||
public RestTemplate portainerRestTemplateDefault() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user