Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .codex-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jfrog",
"version": "0.1.19",
"version": "0.1.20",
"description": "JFrog skills and the JFrog MCP server for Codex \u2014 interact with the JFrog Platform.",
"author": {
"name": "JFrog",
Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/sync-modules-vendor.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"repo": "JFROG/jfrog-agent-hooks",
"pin": "jfrog-agent-hooks/v0.16.2",
"pin": "jfrog-agent-hooks/v0.18.0",
"paths": [
"modules"
]
Expand Down
66 changes: 20 additions & 46 deletions modules/core/agent-guard-check.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import process from "node:process";

import { isMainEntry } from "./entry.mjs";
import { jfInvocation } from "./jf-process.mjs";
import { resolveAiGovernanceConfig } from "./jfrog-ai-governance-config.mjs";
import { skillsProductUserAgent } from "./jf-user-agent.mjs";
import { proxyFetch } from "./proxy-fetch.mjs";

Expand Down Expand Up @@ -62,15 +63,13 @@ function makeDebug(env, debug) {
}

/**
* Resolve credentials from Path A (environment variables) or Path B
* (JFrog CLI configuration).
* Resolve credentials from the JFrog CLI config of one server: `serverId`, or
* the AI Governance server from setup.json when none is given.
*
* Intentionally distinct from `jf-identity.mjs`:
* - package-resolution identity is always `jf config` and may use Basic auth;
* - Agent Guard's settings probe needs a Bearer access token, and mirrors the
* AG CLI by preferring JFROG_URL/JF_URL + access token when set.
* - When `serverId` is set: that jf server first, then env, never the default
* CLI server. Without `serverId`: env first, then default `jf config export`.
* - package-resolution identity is the jf default server and may use Basic auth;
* - Agent Guard's settings probe needs a Bearer access token for the AI
* Governance server. JFROG_URL/JF_URL credentials are not used.
* Do not reuse getPlatformIdentity() here without preserving that contract.
*
* @param {{
Expand All @@ -85,63 +84,38 @@ function makeDebug(env, debug) {
export function resolveAgentGuardCredentials(opts = {}) {
const env = opts.env ?? process.env;
const debug = makeDebug(env, opts.debug);
const explicitServerId = opts.serverId?.trim() || undefined;
const execFn = opts.execFileSyncFn ?? execFileSync;

if (explicitServerId) {
const fromCli = resolveFromCliConfig({
serverId: explicitServerId,
env,
execFileSyncFn: execFn,
debug,
platform: opts.platform,
});
if (fromCli) return fromCli;
debug(
"Explicit server ID did not resolve via jf config; falling back to env credentials.",
);
}

const envUrl = envLookup(env, "JFROG_URL", "JF_URL");
const envToken = envLookup(env, "JFROG_ACCESS_TOKEN", "JF_ACCESS_TOKEN");
if (envUrl && envToken) {
debug("Using credentials from environment variables (Path A).");
return {
baseUrl: envUrl,
token: envToken,
source: "environment variables",
};
let serverId = opts.serverId?.trim() || undefined;
if (!serverId) {
const config = resolveAiGovernanceConfig({ env, log: { debug } });
if (config.status !== "ok" && config.status !== "no_project") {
debug(`No AI Governance server (${config.status}).`);
return null;
}
serverId = config.serverId;
}
debug(
"Environment credentials incomplete; trying JFrog CLI config (Path B).",
);

if (explicitServerId) return null;
return resolveFromCliConfig({
serverId: undefined,
serverId,
env,
execFileSyncFn: execFn,
execFileSyncFn: opts.execFileSyncFn ?? execFileSync,
debug,
platform: opts.platform,
});
}

/**
* @param {{
* serverId?: string,
* serverId: string,
* env?: NodeJS.ProcessEnv,
* execFileSyncFn?: typeof execFileSync,
* debug?: (message: string) => void,
* platform?: NodeJS.Platform,
* }} opts
*/
function resolveFromCliConfig(opts) {
const debug = opts.debug ?? (() => {});
const env = opts.env ?? process.env;
const execFn = opts.execFileSyncFn ?? execFileSync;
const exportArgs = opts.serverId
? ["config", "export", opts.serverId]
: ["config", "export"];
const invocation = jfInvocation(exportArgs, {
const invocation = jfInvocation(["config", "export", opts.serverId], {
env,
platform: opts.platform,
});
Expand Down Expand Up @@ -362,7 +336,7 @@ export async function runAgentGuardCheck(opts = {}) {
return {
code: EXIT_DISABLED,
reason:
"Disabled: JFROG_URL/JF_URL + access token not set and no default JF CLI config found",
"Disabled: no AI Governance server with an access token in the JF CLI config",
};
}

Expand Down
Loading
Loading