feat(verifiedpermissions): run Cedar from the floci-sidecar-cedar image (#3799)

* feat(verifiedpermissions): run Cedar from the floci-sidecar-cedar image

The Cedar sidecar now comes from floci-io/floci-sidecars as
floci/floci-sidecar-cedar, pinned to an exact version because a cached
:latest is never re-pulled. CedarSidecarManager reads the contract JSON
that the image's /health returns: a sidecar speaking another contract
major is refused immediately with a message naming the image and the
FLOCI_SERVICES_VERIFIEDPERMISSIONS_CEDAR_IMAGE and _CEDAR_URL settings
to change, instead of polling for thirty seconds or failing later on a
request. A pre-configured URL is probed the same way. A sidecar whose
health body is not JSON predates the contract and is accepted with a
one-time warning.

* test(verifiedpermissions): exercise the published Cedar image

VerifiedPermissionsIntegrationTest no longer boots the in-tree sidecar in
process: CedarSidecarManager starts the pinned image through Docker, the
same path production takes, under a vp-test resource namespace so the
manager's remove-before-start cannot kill a developer's live sidecar. It
is skipped without Docker, and locally when the image is not present; in
CI a missing image fails. VerifiedPermissionsServiceTest keeps its
reject-before-persist coverage against a fake sidecar answering 400, and
CedarSidecarClientTest pins the request shapes and the 200/400/other
mapping Floci owns.

* chore(build): drop the in-tree Cedar sidecar

sidecars/cedar now lives in floci-io/floci-sidecars as cedar/ with its
history. The build-helper test source root and the test-scoped cedar-java
dependency existed only to boot that server inside the test JVM; the
tests now run against the published image, so both go, along with the
.dockerignore allowlist entry that let the sidecar Dockerfile see its
sources from the repository root context.

* ci: stop publishing the Cedar sidecar from this repository

The release, nightly and reusable image workflows no longer build a
Cedar image or record it in the provenance manifest; the sidecar is
released from floci-io/floci-sidecars on its own cadence. The
compatibility workflow no longer builds and starts the sidecar by hand:
Floci pulls the pinned image itself over the mounted socket onto
compat-net, exactly as it already does for floci-duck. The unit-test
shards prefetch the pinned image, reading the tag from application.yml
so the two cannot drift.

The floci/floci:*-cedar tags stop at this change; whether the next
release cut retags the sidecar image under the old name for a
deprecation window is a release decision, not a workflow default.

* docs(verifiedpermissions): document the external Cedar sidecar image

The Verified Permissions page names floci/floci-sidecar-cedar, why it is
pinned to an exact version, how to pre-pull it, where its API and the
sidecar contract are documented, and what a contract mismatch looks
like. The README's Docker integration table gains the Verified
Permissions row it never had. AGENTS.md records the sidecar rule: own
repository, no tag suffix on the Floci image, no :latest default, the
sidecar releases first, and how a sidecar is tested from here.
This commit is contained in:
Hector Ventura authored and GitHub committed 2026-09-17 09:16:20 -04:00
1 parent f004aeaad5
commit 892927ceb5
21 files changed
+480 -766

No files matched your search

@@ -998,7 +998,7 @@ public interface EmulatorConfig {
/** When set, Floci uses this URL and skips Cedar sidecar container management. */
Optional<String> cedarUrl();
@WithDefault("floci/floci:latest-cedar")
@WithDefault("floci/floci-sidecar-cedar:1.1.0")
String cedarImage();
}
@@ -1,5 +1,8 @@
package io.github.hectorvent.floci.services.verifiedpermissions;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.docker.ContainerBuilder;
import io.github.hectorvent.floci.core.common.docker.ContainerLifecycleManager;
@@ -13,13 +16,30 @@ import jakarta.enterprise.event.Observes;
import jakarta.inject.Inject;
import org.jboss.logging.Logger;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
/** Lazily starts and manages the Cedar 4 sidecar used by Amazon Verified Permissions. */
/**
* Lazily starts and manages the Cedar 4 sidecar used by Amazon Verified Permissions.
*
* <p>The sidecar is the {@code floci/floci-sidecar-cedar} image from floci-io/floci-sidecars. Its
* {@code GET /health} answers the sidecar contract: {@code {"status","name","version","contract"}}.
* A sidecar speaking a different contract major fails fast with a message naming the fix, rather
* than surfacing later as an unexplained request error. A sidecar whose health body is not JSON
* predates the contract and is accepted with a warning.
*/
@ApplicationScoped
public class CedarSidecarManager {
/** The sidecar contract major this manager speaks; see docs/contract.md in floci-io/floci-sidecars. */
static final String REQUIRED_CONTRACT = "1";
static final String IMAGE_ENV = "FLOCI_SERVICES_VERIFIEDPERMISSIONS_CEDAR_IMAGE";
static final String URL_ENV = "FLOCI_SERVICES_VERIFIEDPERMISSIONS_CEDAR_URL";
private static final Logger LOG = Logger.getLogger(CedarSidecarManager.class);
private static final String CONTAINER_NAME = "floci-cedar";
private static final int CEDAR_PORT = 8180;
@@ -29,6 +49,8 @@ public class CedarSidecarManager {
private final ContainerBuilder containerBuilder;
private final ContainerLifecycleManager lifecycleManager;
private final EmulatorConfig config;
private final ObjectMapper objectMapper;
private final AtomicBoolean contractReported = new AtomicBoolean();
private volatile String resolvedUrl;
private volatile String containerId;
@@ -36,10 +58,12 @@ public class CedarSidecarManager {
@Inject
public CedarSidecarManager(ContainerBuilder containerBuilder,
ContainerLifecycleManager lifecycleManager,
EmulatorConfig config) {
EmulatorConfig config,
ObjectMapper objectMapper) {
this.containerBuilder = containerBuilder;
this.lifecycleManager = lifecycleManager;
this.config = config;
this.objectMapper = objectMapper;
}
public synchronized boolean isAvailable() {
@@ -71,7 +95,11 @@ public class CedarSidecarManager {
}
Optional<String> configured = config.services().verifiedpermissions().cedarUrl();
if (configured.isPresent() && !configured.get().isBlank()) {
resolvedUrl = trimTrailingSlash(configured.get());
String url = trimTrailingSlash(configured.get());
// Best effort: a sidecar that is not up yet is reported by the first real call,
// but a sidecar speaking the wrong contract is refused here, once, with the fix.
probeHealth(url);
resolvedUrl = url;
LOG.infov("Using pre-configured Cedar sidecar URL: {0}", resolvedUrl);
return resolvedUrl;
}
@@ -116,18 +144,63 @@ public class CedarSidecarManager {
LOG.infov("Cedar sidecar is ready at {0}", resolvedUrl);
}
/**
* {@code false} means not ready yet (connection refused, non-200, timeout). A sidecar that
* answers but speaks another contract major throws instead, so callers never retry it.
*/
private boolean probeHealth(String baseUrl) {
try {
HttpURLConnection connection = (HttpURLConnection) URI.create(baseUrl + "/health").toURL().openConnection();
connection.setConnectTimeout(500);
connection.setReadTimeout(500);
return connection.getResponseCode() == 200;
} catch (Exception e) {
if (connection.getResponseCode() != 200) {
return false;
}
String body;
try (InputStream in = connection.getInputStream()) {
body = new String(in.readAllBytes(), StandardCharsets.UTF_8);
}
checkContract(baseUrl, body);
return true;
} catch (IOException e) {
LOG.debugv(e, "Cedar sidecar health probe failed for {0}", baseUrl);
return false;
}
}
private void checkContract(String baseUrl, String body) {
JsonNode health = parseHealth(body);
if (health == null || !health.hasNonNull("contract")) {
if (contractReported.compareAndSet(false, true)) {
LOG.warnv("Cedar sidecar at {0} predates the sidecar contract (health body is not contract JSON); "
+ "it still works, but move to floci/floci-sidecar-cedar to get version checks", baseUrl);
}
return;
}
String contract = health.path("contract").asText();
String name = health.path("name").asText("unknown");
String version = health.path("version").asText("unknown");
if (!REQUIRED_CONTRACT.equals(contract)) {
throw new IllegalStateException("Cedar sidecar at " + baseUrl + " (" + name + " " + version
+ ") speaks sidecar contract " + contract + " but this Floci requires contract "
+ REQUIRED_CONTRACT + ". Set " + IMAGE_ENV + " (currently "
+ config.services().verifiedpermissions().cedarImage() + ") or " + URL_ENV
+ " to a compatible sidecar.");
}
if (contractReported.compareAndSet(false, true)) {
LOG.infov("Cedar sidecar {0} {1} (contract {2}) at {3}", name, version, contract, baseUrl);
}
}
private JsonNode parseHealth(String body) {
try {
return objectMapper.readTree(body);
} catch (JsonProcessingException e) {
LOG.debugv(e, "Cedar sidecar health body is not JSON: {0}", body);
return null;
}
}
private void waitForHealth(String baseUrl) {
long deadline = System.currentTimeMillis() + HEALTH_POLL_MAX_MS;
while (System.currentTimeMillis() < deadline) {