Everything on this page is auto-configured. Each feature only switches on when its trigger is present, so you pay for nothing you do not use.

Feature Activated when

SpiffeIdentitySource bean

a Workload API socket is found, or agentless mode is configured

spiffe SSL bundle

an identity source exists

Extra bundles with their own allow-list

spiffe.ssl.bundles.<name>.allowed-ids is set

Peer authorization filter

web app and spiffe.mtls.server.allowed-ids is set

@SpiffePeer argument

web app (servlet or WebFlux)

Spring Security integration

Spring Security is on the classpath

JWT-SVID client support

always as beans; on every client with spiffe.jwt.client.auto-apply=true

JWT-SVID resource server

spiffe.jwt.resource-server.audiences is set

Health and info

Actuator is on the classpath

The identity source

SpiffeIdentitySource is the one bean everything else builds on. Inject it when you need the identity directly:

Method Returns

spiffeId()

this workload’s SPIFFE ID

x509Svid()

the current X.509-SVID (certificate chain and private key)

x509Bundles()

the trusted X.509 bundles, one per trust domain

snapshot()

SVID, bundles and validity, read atomically

fetchJwtSvid(audience, …​)

a JWT-SVID for the audiences, cached until it nears expiry

jwtBundles()

the JWT signing keys used to validate inbound JWT-SVIDs

addListener(listener)

a callback on every rotation

sourceType()

where the identity comes from, such as workload-api or swa-agentless

identity.addListener(snapshot -> log.info("SVID rotated, now valid until {}", snapshot.expiresAt()));

The spiffe SSL bundle

The starter registers a Spring Boot SSL bundle named spiffe. Anything in Spring Boot that accepts a bundle name accepts it:

Where How

Embedded server (Tomcat or Reactor Netty)

server.ssl.bundle=spiffe

Every Boot-built HTTP client

spring.http.clients.ssl.bundle=spiffe

One RestClient

builder.apply(restClientSsl.fromBundle("spiffe"))

One WebClient

builder.apply(webClientSsl.fromBundle("spiffe"))

Rotation without restarts

When the agent pushes a new SVID, the starter updates the bundle:

  • Tomcat reloads its certificate from the bundle.

  • Reactor Netty and every HTTP client read the current SVID at each TLS handshake through live key and trust managers.

Neither needs a restart, and the integration tests rotate both servers while they run.

SPIFFE ID checks instead of hostnames

SVIDs normally carry no DNS name, so classic hostname verification would fail. The starter’s trust manager checks the peer’s SPIFFE ID instead, and plain HTTPS clients keep working. See the FAQ for the one client that needs care.

One bundle per upstream service

When a client must only ever talk to one service, give it its own bundle and allow-list. The TLS handshake then fails for any other server, even one from your own trust domain:

spiffe:
  ssl:
    bundles:
      orders:
        allowed-ids: spiffe://example.org/ns/shop/sa/orders
RestClient orders = builder.apply(ssl.fromBundle("orders")).build();

Authorizing callers by SPIFFE ID

Set an allow-list and the starter adds a filter to servlet and WebFlux applications:

spiffe:
  mtls:
    server:
      allowed-ids:
        - spiffe://example.org/ns/shop/sa/frontend
        - spiffe://example.org/ns/ops/*
      exclude-paths: /actuator/**,/error     # the default
  • No client certificate: 401 Unauthorized.

  • A SPIFFE ID that is not allowed: 403 Forbidden.

  • An empty list turns enforcement off.

ID patterns

Every allowed-ids property in the starter accepts three forms:

Pattern Matches

spiffe://example.org/ns/a/sa/b

exactly that workload

spiffe://example.org/ns/a/*

any ID under that path

spiffe://example.org

any ID in the trust domain

Knowing who called: @SpiffePeer

Controllers can receive the caller’s SPIFFE ID as an argument, in Spring MVC and WebFlux alike:

@GetMapping("/hello")
Map<String, String> hello(@SpiffePeer SpiffeId caller) {
    return Map.of("caller", caller.toString());
}

Spring Security

With Spring Security on the classpath, the starter provides:

  • SpiffeIdX509PrincipalExtractor, which makes the SPIFFE ID the authenticated principal of an X.509 login;

  • SpiffeAuthorizationManagers.hasSpiffeId(…​) and inTrustDomain(…​), which authorize requests on that ID with the same patterns.

@Bean
SecurityFilterChain security(HttpSecurity http, SpiffeIdX509PrincipalExtractor extractor) throws Exception {
    return http
        .x509(x509 -> x509
            .x509PrincipalExtractor(extractor)
            .userDetailsService(id -> User.withUsername(id).password("").authorities("ROLE_WORKLOAD").build()))
        .authorizeHttpRequests(requests -> requests
            .requestMatchers("/admin/**").access(hasSpiffeId("spiffe://example.org/ns/ops/*"))
            .anyRequest().access(inTrustDomain("example.org")))
        .build();
}

JWT-SVIDs on outbound calls

Use JWT-SVIDs when TLS does not reach the service end to end, for example behind an ingress or a service mesh that terminates it. The starter provides an interceptor for RestClient and an exchange filter for WebClient:

RestClient payments = builder
    .baseUrl("https://payments.internal")
    .requestInterceptor(spiffeJwtClientHttpRequestInterceptor)
    .build();

The audience of each token is resolved in this order:

  1. a request attribute: .attribute(SpiffeJwtAudienceResolver.AUDIENCE_ATTRIBUTE, "payments");

  2. the target host: spiffe.jwt.client.audiences.<host>;

  3. the default: spiffe.jwt.client.default-audience.

spiffe:
  jwt:
    client:
      audiences:
        payments.internal: spiffe://example.org/payments
      default-audience: internal-apis
      auto-apply: true    # add the token to every RestClient, RestTemplate and WebClient Boot builds

Tokens are cached per audience and renewed at half-life, or spiffe.jwt.client.refresh-margin before expiry, whichever comes first.

Validating inbound JWT-SVIDs

Name the audiences you accept, and Spring Security’s resource server validates bearer JWT-SVIDs against the agent’s JWT bundles:

spiffe:
  jwt:
    resource-server:
      audiences: spiffe://example.org/payments
      allowed-ids: spiffe://example.org/ns/shop/*    # optional: restrict callers too
@Bean
SecurityFilterChain api(HttpSecurity http) throws Exception {
    return http
        .authorizeHttpRequests(requests -> requests.anyRequest().authenticated())
        .oauth2ResourceServer(oauth2 -> oauth2.jwt(Customizer.withDefaults()))
        .build();
}

The JWT’s sub is the caller’s SPIFFE ID:

@GetMapping("/api/payments")
String payments(@AuthenticationPrincipal Jwt jwt) {
    return "called by " + jwt.getSubject();
}

Both servlet (SpiffeJwtDecoder) and reactive applications are supported.

Health and info

With Actuator present, the starter contributes:

  • a spiffe health indicator, which is DOWN when the SVID is missing, expired, or has less than spiffe.health.min-remaining (5 minutes by default) left, a sign that rotation has stalled;

  • a spiffe info contributor with the SPIFFE ID, the identity source and the SVID validity.

Disable either one the usual Spring Boot way: management.health.spiffe.enabled=false or management.info.spiffe.enabled=false.

Next steps

SPIFFE Spring Boot is an independent open-source project under the Apache License 2.0. It is not affiliated with or endorsed by the SPIFFE project, the CNCF, or Broadcom (Spring). SPIFFE, SPIRE, Spring and Spring Boot are trademarks of their respective owners.

GitHub · Issues · Sample