<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by ANSHUL MITTAL on Medium]]></title>
        <description><![CDATA[Stories by ANSHUL MITTAL on Medium]]></description>
        <link>https://medium.com/@anshul-mittal?source=rss-6487adb71090------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*nR2nldoP0QvgPf8L.</url>
            <title>Stories by ANSHUL MITTAL on Medium</title>
            <link>https://medium.com/@anshul-mittal?source=rss-6487adb71090------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 03:16:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anshul-mittal/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Your AI-Built SaaS Works. Here Are 10 Things It Doesn’t Do Yet.]]></title>
            <link>https://anshul-mittal.medium.com/your-ai-built-saas-works-here-are-10-things-it-doesnt-do-yet-dcaedaa1d4d6?source=rss-6487adb71090------2</link>
            <guid isPermaLink="false">https://medium.com/p/dcaedaa1d4d6</guid>
            <category><![CDATA[saas]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[ANSHUL MITTAL]]></dc:creator>
            <pubDate>Mon, 30 Nov 2026 07:46:00 GMT</pubDate>
            <atom:updated>2026-11-30T07:46:00.603Z</atom:updated>
            <content:encoded><![CDATA[<h3>A coding agent gets you to a working demo in days. These are the gaps between that demo and a product strangers can trust with their data and their money, with a test for each.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ka38sqfYn95j9uOIunQwEA.png" /></figure><p>Ask a coding agent for a B2B SaaS, and you’ll get something impressive: sign-up, a dashboard, CRUD screens, a payment page, a test suite that passes. Click around, and it all works.</p><p>That’s the trap. A demo answers one question: <em>does it work for me?</em> A product has to answer a harder one: <em>does it work correctly for every customer at once, including when something goes wrong, someone retries, or someone tries to break it?</em></p><p>Agents are very good at the first question. They’re not careless; their mistakes are <strong>plausible</strong>. They fill every gap in your instructions with a reasonable guess. And production readiness is mostly made of things nobody put in the instructions, because the demo didn’t need them.</p><p>Here are ten gaps between an agent-built demo and a production SaaS. For each: what the demo usually does, what production needs, and a test that proves you’ve closed it.</p><h3>Isolation</h3><h3>1. Tenant isolation is assumed, not proven</h3><p><strong>The demo:</strong> every query filters by tenant_id, and you&#39;re the only tenant, so you&#39;ve never seen another customer&#39;s data.</p><p><strong>Production needs:</strong> proof that customer A can’t read, change or delete customer B’s data through <em>any</em> endpoint, plus a database safety net (row-level security that the app’s role can’t bypass) for the query that forgets its filter.</p><p><strong>The test:</strong> seed two tenants. For every endpoint, try as A to read, list, update and delete B’s records, including passing B’s IDs inside request bodies. Every attempt must fail. Write this suite before the endpoints exist, so it starts red.</p><p>I covered five ways the database net itself leaks in <a href="https://anshul-mittal.medium.com/row-level-security-is-on-your-tenants-can-still-see-each-others-data-95a3db6bf88d">an earlier article</a>.</p><h3>2. Errors tell attackers what exists</h3><p><strong>The demo:</strong> requesting another tenant’s record returns 403 Forbidden, and validation errors helpfully echo what you sent.</p><p><strong>Production needs:</strong> 404 Not Found for anything outside the caller&#39;s tenant, because a 403 confirms the ID exists. Error messages that never quote another tenant&#39;s rows or input back.</p><p><strong>The test:</strong> in the isolation suite, assert the <em>status code</em>, not just “it failed”. Add a case where a validation error is triggered with another tenant’s ID and check the response body doesn’t contain it.</p><h3>Money</h3><h3>3. Billing webhooks are trusted and processed once</h3><p><strong>The demo:</strong> the payment provider calls your webhook, the handler marks the customer as paid, done.</p><p><strong>Production needs:</strong> providers retry, and they don’t promise order. A webhook can arrive twice, late, or after a newer one. The handler must verify the signature, ignore duplicates, and never let an old event overwrite newer state:</p><pre>CREATE TABLE billing_events (<br>  event_id    text PRIMARY KEY,<br>  received_at timestamptz NOT NULL DEFAULT now()<br>);</pre><pre>-- first statement in the same transaction as the state change<br>INSERT INTO billing_events (event_id) VALUES ($1)<br>ON CONFLICT DO NOTHING<br>RETURNING event_id;<br>-- no row back = already processed: return 200 and stop</pre><p>For ordering, compare the event’s timestamp with the one you last applied, or re-fetch the subscription from the provider instead of trusting the payload.</p><p><strong>The test:</strong> replay the same event twice, deliver “cancelled” before “renewed”, and send one with a bad signature. Paid status must end up right in all three.</p><h3>4. Plan limits are scattered through the code</h3><p><strong>The demo:</strong> if (user.plan === &#39;pro&#39;) in a dozen places.</p><p><strong>Production needs:</strong> limits in one table (plan, limit_key, limit_value) checked by one function, checkLimit(tenantId, key). Otherwise every pricing change is a hunt through the codebase, and the agent will add the thirteenth check with a slightly different rule.</p><p><strong>The test:</strong> a unit test per limit throughcheckLimit, and a CI grep that fails on plan names in feature code.</p><h3>Trust</h3><h3>5. Nothing records who changed what</h3><p><strong>The demo:</strong> no audit log, or one that’s written “after” the change, in a separate call that can fail.</p><p><strong>Production needs:</strong> every state change writes an audit row <strong>in the same transaction</strong> as the change, so you can’t have one without the other. And the log is append-only, enforced by the database, not by good intentions:</p><pre>REVOKE UPDATE, DELETE, TRUNCATE ON audit_log FROM app_user;<br>GRANT  INSERT, SELECT           ON audit_log TO   app_user;</pre><p><strong>The test:</strong> for each state-changing endpoint, assert the audit row exists after success and doesn’t exist after a forced failure. Assert that UPDATE audit_log as the app role errors.</p><h3>6. Customers can’t take their data or leave</h3><p><strong>The demo:</strong> no export, and “delete account” removes the user row and leaves everything else behind.</p><p><strong>Production needs:</strong> an owner can export all their tenant’s data and delete the workspace completely, within a stated time. Customers ask for this, contracts require it, and regulators may insist on it. The hard part isn’t the code: it’s the business decisions the agent will otherwise guess. How long is audit history kept? Is there a grace period before deletion? Can a deleted workspace be restored?</p><p><strong>The test:</strong> export a seeded tenant and check every tenant-owned table is represented. Delete it and assert zero rows remain for that tenant_id in every table, by querying the catalogue for all tables with a tenant_id column, so a new table can&#39;t be forgotten.</p><h3>Outside the request</h3><h3>7. Background jobs forget which tenant they’re working for</h3><p><strong>The demo:</strong> a scheduler runs every minute, picks up due work across all tenants, and processes it in one loop.</p><p><strong>Production needs:</strong> two things the demo never hits. First, nothing sets the tenant for a background job, so each job must take tenant_id from the row it&#39;s processing and pass it explicitly to every call. Second, one tenant&#39;s bad data must not stall everyone: process each item in its own transaction, record a failure once, and move on.</p><p><strong>The test:</strong> seed due work for three tenants where the middle one’s data makes the job throw. Assert the other two are processed, and the failure is recorded once, not retried forever.</p><h3>8. Inbound webhooks write before they verify</h3><p><strong>The demo:</strong> a webhook arrives from Slack, a payment provider or a messaging API; the handler reads the account ID from the payload, looks up the tenant and records the event.</p><p><strong>Production needs:</strong> the tenant may only be resolved from the payload <em>after</em> the provider’s signature is verified, and nothing is written before that check. Otherwise, anyone who can reach the URL can write into any tenant by sending the right account ID.</p><p><strong>The test:</strong> send a correctly shaped payload with a missing or wrong signature and assert nothing changed in the database, not just that the response was 401.</p><h3>Operations</h3><h3>9. Logs and config leak secrets</h3><p><strong>The demo:</strong> default HTTP logging, which records every header, and a config file that falls back to a development encryption key “so it runs locally”.</p><p><strong>Production needs:</strong> cookies, tokens, API keys and decrypted credentials are redacted in the logger configuration, for example with pino:</p><pre>pino({ redact: [&#39;req.headers.cookie&#39;, &#39;req.headers.authorization&#39;] })</pre><p>And the app <strong>refuses to start in production</strong> without an explicit encryption key. A silent fallback means production encrypts customer credentials with a key that sits in your git history.</p><p><strong>The test:</strong> send a request with a known cookie value and assert it never appears in captured log output. Start the app with production settings and no key, and assert it exits.</p><h3>10. You can’t see which customer is having a bad day</h3><p><strong>The demo:</strong> logs exist, somewhere, as one stream.</p><p><strong>Production needs:</strong> every log line, trace and metric tagged with tenant_id (never with secrets), so you can see errors, latency and usage per customer, and spot the one whose account is failing before they email you. Pair it with deploys that a human triggers and migrations that only move forward.</p><p><strong>The test:</strong> this one is a review check rather than a unit test: pick a recent error and confirm you can answer “which tenant, which request, what changed” from your tooling in under five minutes.</p><h3>Why agents skip these, and how to stop it</h3><p>None of these gaps is hard to build. An agent will implement every one of them competently <em>once it’s asked to</em>. The problem is that nobody asks, because the demo works without them.</p><p>So don’t rely on the agent to think of them:</p><ul><li><strong>Put them in the spec before any feature code exists</strong>, as non-functional requirements with acceptance criteria, tenancy first.</li><li><strong>Make each one a task card</strong> with the edge cases written out: the replay, the out-of-order event, the bad row, the missing signature.</li><li><strong>Decide the business rules yourself:</strong> retention, deletion delay, restore. An agent guessing a retention period is a plausible mistake waiting to happen.</li><li><strong>Spend your review time where the risk is:</strong> tenancy, auth, billing and deletion. The tests already cover the CRUD.</li></ul><p>A coding agent makes implementation cheap. It doesn’t make judgment cheap. The demo is the easy 80%; this list is most of the other 20%.</p><p><em>This is part of a series on building a multi-tenant SaaS with coding agents. Start with the overview: </em><a href="https://anshul-mittal.medium.com/building-a-multi-tenant-micro-saas-with-ai-coding-agents-what-you-need-to-get-right-before-you-00386d073875"><em>Building a Multi-Tenant Micro SaaS with AI Coding Agents</em></a><em>.</em></p><h3>Going further</h3><p>My book, <strong>The Multi-Tenant Micro SaaS Playbook</strong>, turns this list into a gated build process: the spec template with these requirements built in, task cards with the edge cases, a full tenant-leak catalogue, and the SaaS plumbing chapter on onboarding, limits, billing, audit, deploys and operations.</p><p>Every copy comes with a <strong>free Claude Code harness pack</strong>: hooks that block the dangerous actions, reviewer agents that check the branch against a review checklist, and a PostgreSQL row-level-security starter kit, all tested before publication.</p><p><a href="https://payhip.com/b/bC45g"><strong>Get the book and the free harness pack →</strong></a></p><p><em>Which gap bit you first? Tell me in the responses.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dcaedaa1d4d6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Claude Code Guardrails Passed Every Test. On Windows, They Blocked Nothing.]]></title>
            <link>https://anshul-mittal.medium.com/my-claude-code-guardrails-passed-every-test-on-windows-they-blocked-nothing-37e3ef868e0b?source=rss-6487adb71090------2</link>
            <guid isPermaLink="false">https://medium.com/p/37e3ef868e0b</guid>
            <category><![CDATA[claude-code]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[ANSHUL MITTAL]]></dc:creator>
            <pubDate>Wed, 25 Nov 2026 06:22:51 GMT</pubDate>
            <atom:updated>2026-11-25T06:22:51.934Z</atom:updated>
            <content:encoded><![CDATA[<h3>A hook that cannot start doesn’t fail safe, it fails open. Here’s how I found out, the two-line fix, and the one test that would have caught it.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1-5kI7KMCyKCxdOVTzAYwA.png" /></figure><p>I had built what I thought was a solid safety net for my coding agent.</p><p>A set of Claude Code hooks that refuse the actions an agent must never take on a multi-tenant SaaS: writing a .env file, editing a database migration that has already run, creating a table without tenant isolation, pushing straight to main, force-pushing. Each rule had unit tests, and every one of them was green.</p><p>Then I copied the whole setup into a fresh repository on a Windows machine, started a real Claude Code session, and asked the agent to do the forbidden things on purpose.</p><p>It created .env without a word of protest.</p><p>None of the hooks had fired. Every guard I’d written was silent, and nothing on screen told me anything was wrong.</p><h3>Why the tests didn’t catch it</h3><p>My unit tests called the rule functions directly: <em>given this file path and this content, should the write be refused?</em> Those answers were all correct. The logic was fine.</p><p>What the tests never exercised was the part between Claude Code and my logic: the command line in settings.json that actually launches the hook. And that&#39;s where it broke.</p><p>The hook was registered the way almost every example shows it:</p><pre>{<br>  &quot;type&quot;: &quot;command&quot;,<br>  &quot;command&quot;: &quot;node \&quot;$CLAUDE_PROJECT_DIR/.claude/hooks/guard-files.mjs\&quot;&quot;<br>}</pre><p>That’s a shell command. On macOS and Linux, a POSIX shell expands $CLAUDE_PROJECT_DIR from the environment, and everything works.</p><p>On my Windows machine, the command ran through <strong>PowerShell</strong>. In PowerShell, $CLAUDE_PROJECT_DIR isn&#39;t an environment variable, it&#39;s a PowerShell variable (environment variables are $env:NAME). It doesn&#39;t exist, so it expanded to an empty string. Node was asked to run /.claude/hooks/guard-files.mjs, couldn&#39;t find it, and exited with code 1.</p><h3>Why did exit code 1 mean “allow”</h3><p>This is the part worth remembering even if you never touch Windows.</p><p>Claude Code reads a command hook’s exit code like this:</p><ul><li><strong>Exit 0:</strong> success. The hook may still deny the action through JSON on stdout.</li><li><strong>Exit 2:</strong> blocking error. The action is stopped, and stderr is shown to the agent.</li><li><strong>Anything else:</strong> non-blocking error. It’s noted, and <strong>the action goes ahead.</strong></li></ul><p>A hook that crashes because the script is missing, a config file has a typo, or the input looks unexpected usually exits with 1. Claude Code treats that as a hiccup, not a veto. So <strong>a guard that cannot start lets everything through.</strong> It fails open.</p><p>Nothing about this is a bug in Claude Code. It’s a reasonable default: you don’t want a flaky formatter hook to stop all your work. But it means a security hook and a formatting hook fail in the same way unless you design for the difference.</p><p>There was a second, quieter casualty. My lint hook runs after each edit withasyncRewake, which wakes the agent to fix errors when the hook exits with <strong>2</strong>. Through PowerShell, that 2 arrived as a 1. Lint errors were found, reported nowhere useful, and the agent carried on.</p><h3>The fix, part 1: exec form</h3><p>Claude Code also accepts hooks in <strong>exec form</strong>: the program in command, its arguments in args, and no shell in between.</p><pre>{<br>  &quot;type&quot;: &quot;command&quot;,<br>  &quot;command&quot;: &quot;node&quot;,<br>  &quot;args&quot;: [&quot;${CLAUDE_PROJECT_DIR}/.claude/hooks/guard-files.mjs&quot;],<br>  &quot;timeout&quot;: 15<br>}</pre><p>Claude Code fills in ${CLAUDE_PROJECT_DIR} itself and starts node directly. There&#39;s no shell to misread the variable or rewrite the exit code, so it behaves the same on Windows, macOS and Linux. After the change, a rerun of the same session got the refusal I&#39;d expected all along, and the lint hook started waking the agent to fix its errors.</p><h3>The fix, part 2: make the guard fail closed</h3><p>Exec form fixes this particular launch problem. It doesn’t fix the general one: a guard can still crash for other reasons, and a crash still means “allow”.</p><p>So every guard now runs inside a small wrapper that turns any error into a block:</p><pre>export async function runGuard(guard) {<br>  try {<br>    await guard(await readHookInput());<br>  } catch (err) {<br>    process.stderr.write(<br>      `Guard ${process.argv[1]} failed, so the action is blocked: ${err?.message ?? err}. ` +<br>      &#39;Fix the hook or its config, or ask the human.&#39;);<br>    process.exit(2);<br>  }<br>}</pre><p>A real refusal goes out as a normal JSON deny with a reason the agent can act on. A broken guard exits 2, stops the action, and says why. If my config has a typo, the agent gets stuck and tells me, which is annoying for thirty seconds. That beats months of believing I was protected when I wasn’t.</p><p>I added two tests that launch the hooks as real processes, the way Claude Code does: one checks that a guard denies through stdout, and one feeds a guard input that makes it crash and asserts exit code 2. I then broke the wrapper on purpose to confirm the second test goes red. A test you’ve never seen fail hasn’t proven anything yet.</p><h3>The test that would have caught it</h3><p>Unit tests prove your rules are right. They can’t prove your rules are <em>running</em>.</p><p>The only check that does is the dumbest one: <strong>start a real session and ask the agent to do something forbidden.</strong> “Create a .env file with a dummy key.&quot; If it isn&#39;t refused, your harness isn&#39;t live, whatever your test suite says.</p><p>That takes thirty seconds. Do it on every machine and operating system your team uses, and again after you change settings.json. I now treat it as a step you can&#39;t skip when setting up the project, not a nice-to-have.</p><h3>The same pattern, one more time</h3><p>While testing on the same machine, I found a third instance of the same failure.</p><p>My read-only reviewer agents were configured withtools: Read, Grep, Glob, Bash, so they could run git diff. On Windows, the session&#39;s shell tool wasPowerShell, not Bash. The security reviewer politely reported that it had no shell, couldn&#39;t see the diff, and reviewed what it could. Adding PowerShell to its tools fixed it, and on the next run it caught a cross-tenant foreign key I&#39;d planted, marked it [must fix] and said &quot;not ready&quot;.</p><p>Three different components, one shape: <strong>something meant to protect me degraded quietly instead of failing loudly.</strong></p><h3>What I’d tell anyone building agent guardrails</h3><ol><li><strong>Decide how each hook should fail.</strong> Formatters and linters can fail open. Anything that guards secrets, data or production must fail closed: catch your own errors and exit 2.</li><li><strong>Prefer exec form for hook commands.</strong> Don’t let a shell you didn’t choose sit between Claude Code and your script.</li><li><strong>Test the launch, not just the logic.</strong> Spawn the hook as a process in your tests, including the case where it crashes.</li><li><strong>Prove it live.</strong> Ask the agent to do one forbidden thing in a real session, on every OS your team uses.</li><li><strong>Distrust silence.</strong> A guardrail that has never refused anything might be working, or it might never have run. Find out which.</li></ol><p><em>Tested with Claude Code 2.1.294 and Node.js 24 on Windows 11. Hook behaviour can change between versions, so check the current hooks documentation, and above all, run the live test.</em></p><p><em>This is part of a series on building a multi-tenant SaaS with coding agents. Start with the overview: </em><a href="https://anshul-mittal.medium.com/building-a-multi-tenant-micro-saas-with-ai-coding-agents-what-you-need-to-get-right-before-you-00386d073875"><em>Building a Multi-Tenant Micro SaaS with AI Coding Agents</em></a><em>. For the database side, see </em><a href="https://anshul-mittal.medium.com/row-level-security-is-on-your-tenants-can-still-see-each-others-data-95a3db6bf88d"><em>Row-Level Security Is On. Your Tenants Can Still See Each Other’s Data</em></a><em>.</em></p><h3>Where this came from</h3><p>I found this while testing the companion pack for my book, <strong>The Multi-Tenant Micro SaaS Playbook</strong>: a practical guide to building a multi-tenant SaaS with a coding agent doing most of the typing, without letting one customer see another’s data.</p><p>Every copy comes with the <strong>Claude Code harness pack free</strong>: the hooks from this article (exec form, failing closed), skills, two reviewer agents, and a PostgreSQL row-level-security starter kit. It was all tested in live sessions and against real PostgreSQL 15 and 16 databases before release, which is how this bug got found before a reader hit it.</p><p><a href="https://payhip.com/b/bC45g"><strong>Get the book and the free harness pack →</strong></a></p><p><em>Have you had a guardrail fail silently? I’d like to hear about it in the responses.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=37e3ef868e0b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Row-Level Security Is On. Your Tenants Can Still See Each Other’s Data.]]></title>
            <link>https://anshul-mittal.medium.com/row-level-security-is-on-your-tenants-can-still-see-each-others-data-95a3db6bf88d?source=rss-6487adb71090------2</link>
            <guid isPermaLink="false">https://medium.com/p/95a3db6bf88d</guid>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[saas]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[ANSHUL MITTAL]]></dc:creator>
            <pubDate>Sun, 08 Nov 2026 04:51:05 GMT</pubDate>
            <atom:updated>2026-11-08T04:57:28.756Z</atom:updated>
            <content:encoded><![CDATA[<h3>Five ways a multi-tenant PostgreSQL app leaks across tenants with RLS “enabled”, each reproduced on PostgreSQL 15 and 16, and the fix for each.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LS7OAr5sLxQQpv2vNTsemA.png" /></figure><p>If you run a multi-tenant SaaS on PostgreSQL, row-level security (RLS) is the best safety net you can have. Your application filters every query by tenant; RLS makes sure that a query which <em>forgets</em> its filter still only sees the current tenant’s rows.</p><p>But “RLS is enabled” is a much weaker statement than most teams think. While testing the SQL for a book on building multi-tenant SaaS with coding agents, I wrote a small script that tries to break isolation in the ways real codebases do. Every attack below succeeded on a stock PostgreSQL 15 and 16, with RLS switched on.</p><p>These are exactly the mistakes a coding agent makes: not careless ones, but plausible ones. Each looks correct in a diff.</p><p>The setup is the usual one: one database, every tenant-owned table has a tenant_id column, and the app sets the current tenant in a setting that the policies read:</p><pre>CREATE POLICY tenant_isolation ON employees<br>  USING (tenant_id = NULLIF(current_setting(&#39;app.tenant_id&#39;, true), &#39;&#39;)::uuid);</pre><p>Two tenants, A and B. One employee each: Alice in A, Bob in B.</p><h3>Leak 1: The app connects as the table owner</h3><p>The quickest setup is one database user that runs the migrations <em>and</em> serves the app. It owns every table.</p><pre>-- tenant A is set, RLS is enabled, connected as the table owner<br>SELECT name FROM employees;</pre><pre>name<br>------------------<br> Alice (tenant A)<br> Bob (tenant B)</pre><p>Both tenants. <strong>Table owners bypass RLS by default.</strong> The policy exists and is enabled, and it does nothing for the role that actually runs your queries. Superusers bypass it too, always.</p><p><strong>Fix:</strong></p><ul><li>ALTER TABLE ... FORCE ROW LEVEL SECURITY On every tenant table, so the policy applies to the owner as well. After that, the same query returned only Alice.</li><li>Better still, split the roles: one <strong>owner</strong> role that runs migrations, and an <strong>app</strong> role that owns nothing, isn’t a superuser and has NOBYPASSRLS.</li><li>Make the app refuse to start if it’s connected as the wrong role:</li></ul><pre>SELECT r.rolsuper     AS superuser,<br>       r.rolbypassrls AS bypass_rls,<br>       EXISTS (SELECT 1 FROM pg_tables t WHERE t.tableowner = current_user) AS owns_tables<br>FROM pg_roles r WHERE r.rolname = current_user;<br>-- if any column is true, crash at startup with a clear message</pre><p>A wrong connection string then fails at deploy time, instead of quietly running without isolation for months.</p><h3>Leak 2: A plain foreign key crosses tenants</h3><p>A document belongs to an employee. The obvious schema:</p><pre>CREATE TABLE documents (<br>  id          uuid PRIMARY KEY DEFAULT gen_random_uuid(),<br>  tenant_id   uuid NOT NULL,<br>  employee_id uuid NOT NULL REFERENCES employees (id),<br>  title       text NOT NULL<br>);</pre><p>Now tenant A, connected as the app role with RLS forced on both tables, attaches a document to <strong>Bob, tenant B’s employee</strong>:</p><pre>INSERT INTO documents (tenant_id, employee_id, title)<br>VALUES (&#39;&lt;tenant A&gt;&#39;, &#39;&lt;Bob&#39;&#39;s id&gt;&#39;, &#39;Contract&#39;);<br>-- INSERT 0 1</pre><p>It succeeds. <strong>Foreign-key checks bypass RLS.</strong> The database checks that Bob’s ID exists <em>somewhere</em>, not that it belongs to tenant A. The document’s own policy is happy, because the document’s tenant_id really is A.</p><p>RLS still hides Bob’s row if tenant A joins to employees. But tenant A&#39;s data now points into tenant B&#39;s, and you&#39;ve built two problems:</p><ul><li><strong>An existence oracle.</strong> A random ID fails with a foreign-key error, while Bob’s real ID succeeds. Tenant A can probe whether an ID exists in <em>any</em> tenant.</li><li><strong>A time bomb.</strong> Any code path that follows the link without RLS, such as a background job, an admin report or an email template that renders the employee’s name, will hand B’s data to A.</li></ul><p>How would A get Bob’s ID? IDs leak through URLs, logs, exports, support screenshots and emails. Don’t build isolation on secrecy.</p><p><strong>Fix:</strong> make the tenant part of the key.</p><pre>ALTER TABLE employees ADD UNIQUE (tenant_id, id);</pre><pre>CREATE TABLE documents (<br>  ...<br>  FOREIGN KEY (tenant_id, employee_id) REFERENCES employees (tenant_id, id)<br>);</pre><p>The same insert now fails: violates foreign key constraint &quot;documents_tenant_id_employee_id_fkey&quot;. The database itself refuses the cross-tenant link, whatever the application forgot to validate. Keep validating client-supplied IDs in the app too; this is the net under it.</p><h3>Leak 3: A per-command policy lets a forged tenant_id in</h3><p>USING decides which rows you can see, update and delete. WITH CHECK decides which rows you&#39;re allowed to <em>write</em>. If you skip WITH CHECK on a single policy for all commands, PostgreSQL reuses USING as the check, so this is safe:</p><pre>CREATE POLICY t ON notes<br>  USING (tenant_id = NULLIF(current_setting(&#39;app.tenant_id&#39;, true), &#39;&#39;)::uuid);<br>-- tenant A inserting a row for tenant B:<br>-- ERROR: new row violates row-level security policy for table &quot;notes&quot;</pre><p>Now someone refactors the policy into one per command. Maybe inserts “are validated by the app anyway”, or a migration tool generated them this way:</p><pre>CREATE POLICY sel ON notes FOR SELECT<br>  USING (tenant_id = NULLIF(current_setting(&#39;app.tenant_id&#39;, true), &#39;&#39;)::uuid);<br>CREATE POLICY ins ON notes FOR INSERT<br>  WITH CHECK (tenant_id IS NOT NULL);</pre><p>Tenant A inserts a note with tenant_id = B. It succeeds. Then tenant B logs in:</p><pre>body<br>--------<br> forged</pre><p>Tenant A has just <strong>written into tenant B’s account</strong>. Depending on the table, that’s planted data, a fake invoice line, or a webhook URL that sends B’s events to A.</p><p>Adding a second <em>permissive</em> policy does the same thing, because permissive policies are OR-ed together. One generous policy opens the table, however strict the others are.</p><p><strong>Fix:</strong> always write WITH CHECK explicitly, with the same tenant condition as USING, on every policy that allows writes. Even where PostgreSQL would infer it, the explicit clause keeps the rule visible in every review and survives the next refactor. And check it in CI, not by eye (see the end of this article).</p><h3>Leak 4: The tenant setting outlives the request</h3><p>The app sets the tenant at the start of each request. A natural first version:</p><pre>SET app.tenant_id = &#39;&lt;tenant A&gt;&#39;;</pre><p>With a connection pool, the connection goes back to the pool when the request ends, <strong>with the setting still on it</strong>. The next request that picks up that connection, for any tenant, starts as tenant A:</p><pre>-- next request, nothing set yet<br>SELECT name FROM employees;</pre><pre>next_request_sees<br>-------------------<br> Alice (tenant A)</pre><p>If that next request forgets to set its own tenant, or fails partway through and continues, it reads another customer’s data. This one is nasty because it depends on timing and load, so it rarely appears in tests.</p><p><strong>Fix:</strong> set the tenant <em>inside a transaction</em>, as a transaction-local value:</p><pre>BEGIN;<br>SELECT set_config(&#39;app.tenant_id&#39;, &#39;&lt;tenant A&gt;&#39;, true);  -- true = local to this transaction<br>-- ... all the request&#39;s queries ...<br>COMMIT;</pre><p>After COMMIT, the same next-request query returned <strong>0 rows</strong>. Put this in one data-access function (withTenant(tenantId, fn)) and make it the only way the app can reach the database. That also works behind a pooler in transaction mode, because the setting lives and dies inside one transaction.</p><h3>Leak 5: An “admin shortcut” turns no tenant into every tenant</h3><p>Migrations, maintenance scripts and support tools often run without a tenant. With the policy above, they see nothing, which is annoying, so someone adds a shortcut:</p><pre>CREATE POLICY tenant_isolation ON employees<br>  USING (tenant_id = NULLIF(current_setting(&#39;app.tenant_id&#39;, true), &#39;&#39;)::uuid<br>         OR coalesce(current_setting(&#39;app.tenant_id&#39;, true), &#39;&#39;) = &#39;&#39;);  -- &quot;for admin scripts&quot;</pre><p>It looks harmless: with a tenant set, tenant A still sees only Alice. But now <strong>any request that forgets to set the tenant sees every tenant</strong>:</p><pre>-- no tenant set, connected as the app role<br>SELECT name FROM employees;</pre><pre>name<br>------------------<br> Alice (tenant A)<br> Bob (tenant B)</pre><p>The same thing happens after a transaction that set the tenant has ended, so a code path that runs a query outside the tenant transaction quietly gets the whole table. A coalesce to a &quot;default&quot; tenant does the same kind of damage. The safety net now fails in exactly the case it exists for: the query that forgot its filter.</p><p><strong>Fix:</strong> keep the strict expression, and look at what it does with no tenant:</p><pre>tenant_id = NULLIF(current_setting(&#39;app.tenant_id&#39;, true), &#39;&#39;)::uuid</pre><ul><li>current_setting(..., true) returns NULL instead of raising an error when the setting was never set.</li><li>After a transaction that set it has ended, it returns an empty string. NULLIF(..., &#39;&#39;) turns that intoNULL, so the uuid cast can&#39;t fail.</li><li>tenant_id = NULL matches nothing.</li></ul><p>With no tenant set, the strict policy returned <strong>0 rows</strong>. That’s the property you want: <strong>no tenant means no rows, never all rows.</strong> Admin and maintenance work that genuinely spans tenants should run as a separate, named system role with its own short list of reviewed queries, not through a hole in the app’s policy.</p><h3>Prove it, don’t assume it</h3><p>None of these shows up in a demo, because you’re the only tenant. Most don’t show up in tests, because most tests use one tenant. Here’s what catches them:</p><ol><li><strong>A two-tenant isolation suite.</strong> Seed tenants A and B. For every endpoint, try as A to read, list, update and delete B’s data, including passing B’s IDs in request bodies (that’s how leak 2 gets in). Every attempt must fail, and it should return 404, not 403: a 403 tells the attacker the ID exists. Write this suite <em>before</em> the endpoints, so it starts red and turns green for the right reasons.</li><li><strong>A database policy check in CI.</strong> After migrations run, query the catalogue and fail the build on any tenant table without RLS enabled <em>and forced</em>, without a policy, or with a nullabletenant_id, and on an app role that&#39;s a superuser, can bypass RLS or owns tables. Only the database knows its final state, whichever tool wrote the migration.</li><li><strong>A startup role check</strong> (leak 1), so production can’t silently run as the owner.</li><li><strong>A smoke test</strong> that connects as the app role and runs the five attacks above against a scratch database. They take seconds, and they’re the difference between “RLS is enabled” and “isolation is proven”.</li></ol><p><em>Every result in this article was reproduced on stock PostgreSQL 15 and 16 Docker images, connected as a non-superuser role.</em></p><p><em>This is part of a series on building a multi-tenant SaaS with coding agents. Start with the overview: </em><a href="https://anshul-mittal.medium.com/building-a-multi-tenant-micro-saas-with-ai-coding-agents-what-you-need-to-get-right-before-you-00386d073875"><em>Building a Multi-Tenant Micro SaaS with AI Coding Agents</em></a><em>.</em></p><h3>Going further</h3><p>This is one chapter’s worth of a bigger problem. My book, <strong>The Multi-Tenant Micro SaaS Playbook</strong>, covers the whole path of building a multi-tenant SaaS with a coding agent doing most of the typing:</p><ul><li>the architecture decisions to make first;</li><li>the harness that stops the agent breaking the rules;</li><li>a full catalogue of tenant leaks, covering caches, webhooks, background jobs, logs and admin endpoints, not just the database;</li><li>complete RLS SQL with roles, grants, the CI policy check and the smoke test.</li></ul><p>Every copy comes with a <strong>free Claude Code harness pack</strong>, which includes a PostgreSQL row-level-security starter kit implementing every fix above, tested on PostgreSQL 15 and 16.</p><p><a href="https://payhip.com/b/bC45g"><strong>Get the book and the free harness pack →</strong></a></p><p><em>Found a tenant leak I didn’t cover? Tell me in the responses. I’m collecting them.</em></p><p>Independent article, not affiliated with or endorsed by Anthropic. Claude and Claude Code are trademarks of Anthropic, PBC.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95a3db6bf88d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Multi-Tenant Micro SaaS with AI Coding Agents: What You Need to Get Right Before You…]]></title>
            <link>https://anshul-mittal.medium.com/building-a-multi-tenant-micro-saas-with-ai-coding-agents-what-you-need-to-get-right-before-you-00386d073875?source=rss-6487adb71090------2</link>
            <guid isPermaLink="false">https://medium.com/p/00386d073875</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[ANSHUL MITTAL]]></dc:creator>
            <pubDate>Sat, 07 Nov 2026 05:24:27 GMT</pubDate>
            <atom:updated>2026-11-07T05:24:27.300Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building a Multi-Tenant Micro SaaS with AI Coding Agents: What You Need to Get Right Before You Start Coding</h3><h3>AI coding agents make building software faster. But building a secure, reliable SaaS product requires more than writing prompts and generating code.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4yUZ8NfmfbwKbBMqdJwahw.png" /></figure><h3>The new opportunity</h3><p>A year or two ago, a solo developer building a B2B SaaS product needed months of evenings to reach something a customer would pay for. Today a capable coding agent (Claude Code, Cursor, Codex and the rest) can scaffold the backend, the admin screens, the tests and the CI pipeline in days.</p><p>That changes the economics of the <strong>micro SaaS</strong>: one person or a small team running one focused product for a few hundred paying businesses. You don’t need a team to build it any more. You need a clear idea of the problem, the judgment to make good decisions, and the discipline to check what the agent produces.</p><p>That last part is where most of the risk now sits.</p><h3>The hidden problem</h3><p>Generating an application is not the same as building a production-ready SaaS.</p><p>An agent will happily give you a working demo: sign-up, a dashboard, CRUD screens, a passing test suite. Everything looks finished. But a demo answers one question, <em>does it work for me?</em> while a SaaS product has to answer a much harder one: <em>does it work correctly for every customer at once, including when something goes wrong?</em></p><p>Coding agents are very good at writing code that looks right. Their mistakes are rarely syntax errors or crashes. They’re <strong>plausible assumptions</strong>: a filter applied in most places but not all, an edge case nobody described, a business rule filled in with a reasonable guess. The code is clean, the tests are green, and the assumption sits there unexamined.</p><p>In most software, a wrong assumption gives you a bug. In a multi-tenant SaaS, some wrong assumptions give you a breach.</p><h3>Why multi-tenancy matters</h3><p>A <strong>tenant</strong> is a customer account: usually a company, a workspace or an organisation. A multi-tenant application serves all of them from one codebase and, for a micro SaaS, almost always one database. Every tenant’s data sits in the same tables, separated by a column that records who owns each row.</p><p>This is the right model for a small product: it’s cheap to run, there’s one deployment, and you migrate the schema once. But it carries one non-negotiable requirement:</p><blockquote><strong><em>No tenant may ever see, change or even infer another tenant’s data.</em></strong></blockquote><p>What makes this hard is that “mostly isolated” looks identical to “isolated” until the day it doesn’t. A missing filter passes the demo, because you’re the only tenant. It passes most tests, because most tests use one tenant. It survives your first customers, because they have no reason to probe. Then one day a support email starts with <em>“Why can I see…”</em>, and for a small product that may be the last email you get from that customer, and maybe from their friends too.</p><p>That’s why I treat tenant isolation as <strong>the foundation, not a feature</strong>. It’s designed and tested before any business functionality is built, so every later feature inherits it instead of re-implementing it.</p><h3>Architecture before coding</h3><p>The most valuable work in an agent-built SaaS happens before the agent writes anything. There are a handful of decisions that, once made and written down, the agent should never re-decide.</p><p><strong>How the tenant is identified.</strong> On every request, the application has to know which tenant it’s acting for. The safe answer is that this comes from verified identity, such as the organisation claim in an authenticated token. It never comes from something the client can simply type, like a field in the request body or a query parameter. Any design where the browser <em>tells</em> the server which tenant it is will eventually be abused.</p><p><strong>How isolation is enforced.</strong> Filtering by tenant in application code is necessary but not sufficient. Code forgets. The stronger design enforces isolation in the database too, with PostgreSQL row-level security, so that even a query that forgets its filter can only see the current tenant’s rows. The app’s filters are the first line; the database is the safety net. You want both, and you want the net to be one that the application <em>cannot</em> switch off. That last requirement is subtler than it sounds.</p><p><strong>How data is modelled.</strong> Every tenant-owned table carries the tenant identifier and is indexed by it. Record IDs shouldn’t be guessable. Relationships between records have to stay within one tenant, which raises questions the obvious design doesn’t answer.</p><p><strong>How authorisation works inside a tenant.</strong> Owners, admins and members need different permissions. That’s a second boundary, inside the first.</p><p>Write each of these down as a short <strong>Architecture Decision Record</strong> in the repository. It takes an afternoon. In return, every agent session starts from the same decisions instead of improvising new ones, and when the agent gets something wrong, you can point it at the record rather than arguing in a prompt.</p><h3>The coding-agent harness</h3><p>Here’s the shift that made the biggest difference for me:</p><blockquote><strong><em>Stop asking the agent to remember the rules. Build a system where it can’t break them.</em></strong></blockquote><p>A coding agent is only as reliable as the environment you put it in. I call that environment the <strong>harness</strong>, and it has six parts:</p><ol><li><strong>Instructions and rules</strong>: a short, enforceable rules file the agent reads every session, plus reusable procedures for tasks the build repeats.</li><li><strong>Tools</strong>: the commands, APIs and integrations the agent is allowed to use.</li><li><strong>A sandbox</strong>: where the agent’s code runs, and, critically, what it can’t reach, such as production credentials.</li><li><strong>Orchestration</strong>: planning, implementing and reviewing as separate steps, with tests run after every change.</li><li><strong>Hooks and guardrails</strong>: deterministic code that runs at fixed points and <em>blocks</em> actions that must never happen.</li><li><strong>Observability</strong>: logs, costs and evaluations, so you can see what the agent actually did, not just what it said.</li></ol><p>The fifth is the one most people skip, and it matters most. A sentence in a rules file is a request. A hook that refuses the action is a guarantee. Anything that must <em>never</em> happen (writing secrets, editing a migration that has already run, creating a table without tenant isolation, deploying to production) belongs in a hook, not in a paragraph the agent might skim on a busy day.</p><h3>Build in vertical slices</h3><p>The fastest way to get an unreliable SaaS from an agent is to ask it to “build the app”.</p><p>Instead, break the product into <strong>thin vertical slices</strong>. Each slice goes all the way from database to API to UI to tests, and is small enough for one agent session and one careful human review. Each slice gets a short task card: the goal, the acceptance criteria, the files in scope, the edge cases, and the tenant-isolation cases.</p><p>The order matters. The tenancy foundation comes first: the tenant tables, isolation, authentication and tenant resolution. Then sign-up and membership, then the core workflow, then billing and the rest of the plumbing. Every later slice inherits isolation instead of bolting it on.</p><p>Within each slice, the rhythm is simple: the agent plans without writing code, you approve the plan, it writes failing tests, it implements until they pass, and you review before merging. When the agent gets something wrong, resist the urge to just re-prompt. Ask which fact was missing from the spec, the decision records, or the rules file, add it there, and run the slice again. That’s how the harness gets better instead of your prompts getting longer.</p><h3>Verification is essential</h3><p>Verification is what separates engineering with agents from vibe coding. Each layer catches a different kind of failure:</p><ul><li><strong>Unit and API tests</strong> check business rules and acceptance criteria.</li><li><strong>A tenant isolation suite</strong> seeds two tenants, A and B, and for every endpoint tries, as A, to read, list, update and delete B’s data. Every attempt must fail.</li><li><strong>Database policy checks</strong> confirm that isolation is actually switched on and enforced for every table, and that the application’s database role can’t get around it.</li><li><strong>End-to-end tests</strong> run the real journey, from sign-up to the core workflow to upgrading, with two tenants side by side.</li><li><strong>Human review</strong> covers design, security and scope: everything the tests can’t judge.</li></ul><p>The isolation suite deserves special attention. Write it <em>before</em> the endpoints exist, so it starts red and turns green for the right reasons. On one codebase, a suite written after the fact turned up isolation bugs in code that had already passed review. Nothing was wrong with the reviewers; the bugs simply lived in places a reviewer reading a diff doesn’t look.</p><p>Finally, evaluate the agent’s <em>trajectory</em>, not just its output. Did it run the isolation tests? Did it stay inside the files it was asked to change? A fluent result that skipped verification is more dangerous than a visible error.</p><h3>From prototype to product</h3><p>A multi-tenant app becomes a business when the plumbing exists:</p><ul><li><strong>Onboarding</strong> that takes a new tenant to their first useful result quickly.</li><li><strong>Plans and limits</strong> enforced in one place, never with plan names hard-coded through the feature code.</li><li><strong>Billing</strong>, where the payment provider’s webhooks are the source of truth: verified, idempotent and tested against replays.</li><li><strong>Audit logs</strong> written for every state change and never edited afterwards.</li><li><strong>Data export and deletion</strong>, because customers will ask and regulators may insist.</li><li><strong>Deployment</strong> through environments, with migrations that only move forward, and deploys triggered by a human, never by the agent.</li><li><strong>Monitoring tagged by tenant</strong>, so you can see which customer is having a bad day before they tell you.</li></ul><p>None of these is glamorous, and an agent will build each of them competently once it’s specified. The skill is in specifying them well and in deciding the business rules (retention, deletion delays, limits) before the agent has to guess.</p><h3>Final thoughts</h3><p>AI coding agents have made implementation dramatically cheaper. They haven’t made judgment cheaper. Architecture, tenant isolation, a well-built harness and honest verification are what turn a fast prototype into a product you can confidently put in front of paying customers.</p><p>The good news is that this discipline is learnable, and once it’s in place, it’s what lets you move <em>fast</em>: every slice builds on a foundation you trust, and every mistake the agent makes becomes a rule it can’t make again.</p><h3>Want to go deeper?</h3><p>Building a micro SaaS with AI coding agents is exciting, but getting the architecture, tenant isolation, development workflow and verification right is what separates a quick prototype from a product you can confidently put in front of paying customers.</p><p>I’ve put together a practical guide covering this journey: <strong>The Multi-Tenant Micro SaaS Playbook</strong>.</p><p>It walks through the architecture decisions, the coding-agent harness, the implementation workflow, the verification strategy and the production-readiness work involved in building a multi-tenant SaaS application. Every copy comes with a free Claude Code harness pack, including a PostgreSQL row-level-security starter kit, all tested before publication.</p><p>If you’re a solo founder, indie hacker or developer using AI coding agents to build your next SaaS product, you may find it useful.</p><p><a href="https://medium.com/%7B%7BPURCHASE_LINK%7D%7D">Explore the playbook →</a></p><p><a href="https://payhip.com/b/bC45g"><strong>Get the book and the free harness pack</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=00386d073875" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Secure Oracle Fusion Cloud API Access Using JWT User Assertion: Integrating HCM REST APIs…]]></title>
            <link>https://anshul-mittal.medium.com/secure-oracle-fusion-cloud-api-access-using-jwt-user-assertion-integrating-hcm-rest-apis-c875eb094aec?source=rss-6487adb71090------2</link>
            <guid isPermaLink="false">https://medium.com/p/c875eb094aec</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[jwt]]></category>
            <category><![CDATA[oracle-integration-cloud]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[oracle-fusion]]></category>
            <dc:creator><![CDATA[ANSHUL MITTAL]]></dc:creator>
            <pubDate>Tue, 20 Oct 2026 08:38:58 GMT</pubDate>
            <atom:updated>2026-10-23T03:06:50.307Z</atom:updated>
            <content:encoded><![CDATA[<h3>Secure Oracle Fusion Cloud API Access Using JWT User Assertion: Integrating HCM REST APIs, Financials REST APIs, and BI Publisher SOAP Services in OIC</h3><p>Oracle Fusion Cloud applications support OAuth 2.0 token-based authentication for securing REST API access, with authentication requirements depending on the application configuration and applicable Oracle security policies. In Oracle Fusion, the associated identity domain acts as the authorization server responsible for issuing access tokens. For non-interactive integrations, two-legged OAuth is commonly used, while three-legged OAuth is suitable when authorization involves an interactive end-user flow.</p><p>This article focuses on configuring <strong>two-legged authentication using the JWT User Assertion grant type in OCI IAM (Identity Domains)</strong>. It explains how to configure the confidential application, establish trust using JWT signing keys, configure the OAuth JWT User Assertion in OIC, and use the resulting token to invoke Oracle Fusion Cloud REST and SOAP APIs securely.</p><p><strong>Generate RSA keys for authentication</strong></p><ol><li>Generate a private key (private.key)</li></ol><blockquote>openssl genrsa -out Private.key 2048</blockquote><p>2. Using the created private key, create an X509 certificate (.cer file) containing your public key</p><blockquote>openssl req -new -x509 -key Private.key -out Publickey.cer -days 365</blockquote><p>Please save the Private.key and Publickey.cer files in a separate location. This will require configuration in further setup.</p><p><strong>Create an OAuth confidential application in FA OCI IAM with JWT user assertion</strong></p><ol><li>Log in to the FA OCI IAM.</li><li>Go to the IAM domain for the ERP instance you want to enable OAuth 2.0</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LEJRMSW_GPlJ7JWnxo7WtQ.png" /></figure><p>3. Go to the Integrated Applications → Create a new confidential application</p><p>Give the name: FA_Oauth_JWT_Token_Authentication</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0YOTZTuoL-C-rdJbhALg0Q.png" /></figure><p>4. Edit the Oauth Configuration → Configure the application as a client now</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sRVw1TP01ipNZ2bIaGMcng.png" /></figure><p>Authorization → Select JWT assertion</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/967/1*5D1GJOWo2KYQFs_ZWjcsgw.png" /></figure><p>Client type → select “Trust”</p><p>Import certificate → Import the “Publickey.cer” file created in step 1. Import that certificate in this section. Also give a unique alias name. Please remember this alias name, as we need to provide this name in the header while configuring in the adapter configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ck60DhklRG8w3m0LJMrMag.png" /></figure><p>5. Go to “Token Issuance Policy” → choose Specific and enable Add resources → Click on Add scope → Select your Fusion Cloud instance. You can select the scope visible in the screenshot. Please verify in your environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gsizsNj0q0j-X-KeadJ8tQ.png" /></figure><p>6. Submit and save the application. Activate the application</p><p>Finally, extract the three values from this configuration</p><p>Client ID: you can get it from the application page as below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rAkbBpv8L9UYH5Ezy09JNg.png" /></figure><p>kid: this is the alias name value configured while importing the certificate in step 4</p><p>IDCS domain URL: you will get this from the domain → details</p><p><a href="https://idcs-31382fadd88944b3aa12c6da57fdbade.identity.oraclecloud.com/oauth2/v1/token">https://&lt;idcs-instance&gt;.identity.oraclecloud.com:443</a></p><p><strong>Import the private key created in step 1 into the OIC Certificates.</strong></p><ol><li>Import the private key certificate in OIC Certificates as a sign key</li></ol><p>Select the private key that is created in the very first step to authenticate the client request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3RPf8lVWBjmgiVV47ZsGGA.png" /></figure><p>Remember the alias name. In this case, it is “TESTJWTKEY”. This will be required to enter in the OIC connection to refer to the private key.</p><p><strong>Configure JWT user assertion security in OIC Connection for REST/SOAP</strong></p><ol><li>Go to the OIC connection → configure ERP adapter</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WuAPma7wh1-5wbf96yfl0w.png" /></figure><p><strong>Connection URL:</strong> your Fusion instance URL</p><p><strong>Security Policy: </strong>OAuth using JWT User Assertion</p><p><strong>Access Token URI</strong>: <a href="https://idcs-31382fadd88944b3aa12c6da57fdbade.identity.oraclecloud.com/oauth2/v1/token">https://&lt;idcs-instance&gt;.identity.oraclecloud.com:443</a>/oauth2/v1/token</p><p><strong>JWT Header in JSON format</strong>: create a JSON file and add below content below</p><p>{<br> “alg”: “RS256”,<br> “typ”: “JWT”,<br> “kid”: “&lt;This is the alias name you have given while importing the certificate in OAuth configuration”<br>}</p><p><strong>JWT payload: </strong>create a JSON file and add the content</p><p>{<br> “iss”: “b121b0e2c5004bbbbf4bdcd8”, //client id get it from oauth configuration<br> “sub”: “&lt;integration user&gt;”, // this is a fusion user which you want to invoke <br> “aud”: “<a href="https://identity.oraclecloud.com/">https://identity.oraclecloud.com/</a>&quot;,<br> “iat”: 1596271154,<br> “exp”: 1918081154<br>}</p><p>example value</p><p>{<br> “iss”: “b121b0e2c5004bbbbf4bdcd8e68f6b96”,<br> “sub”: “integraion user”,<br> “aud”: “<a href="https://identity.oraclecloud.com/">https://identity.oraclecloud.com/</a>&quot;,<br> “iat”: 1596271154,<br> “exp”: 1918081154<br>}</p><p><strong>JWT private key alias:</strong> enter the value that you have configured while importing the sign key certificate in the OIC certificate section.</p><p><strong>Scope URL: </strong>urn:opc:resource:faaas:fa:&lt;fusion_pod_id&gt;urn:opc:resource:consumer::all</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZRPAxZxcuKL163rGEzlQPw.png" /></figure><p>2. Save and test the connection</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v8J-xqi-bVTA51PmLpWiZQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c875eb094aec" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>