Frodo + Service Accounts = Secure CI/CD in ForgeRock Identity Cloud

Last updated on January 19th, 2023 at 08:07 pm


Frodo, short for ForgeROck Do, is an open source and community project hosted on GitHub to help administrators of the ForgeRock Identity Platform automate configuration tasks and build secure continuous integration and continuous deployment (CI/CD) pipelines.

Frodo comes in two flavors: A CLI and a JavaScript (node.js) library packaged and published as two individual NPM packages. The CLI is also available as a single-file binary for Linux, Windows, and MacOS. Support for the new Service Accounts in ForgeRock Identity Cloud was added in Frodo CLI v0.20.0 and Frodo Library v0.18.0.

Why Service Accounts?

Before service accounts were an option, administrators created tenant admin accounts without MFA and used those for automated configuration management. While that approach worked, it wasn’t perfect and created unnecessary challenges: 

  • These admin accounts used as service accounts had more privileges than necessary with no option to limit.
  • These admin accounts usually didn’t have MFA enabled, as that breaks headless logins.
  • Different APIs required different types of tokens, making it difficult for tools like Frodo to operate:
    • Access Management APIs (/am) required the traditional session token for all configuration endpoints.
    • Identity Management APIs (/openidm) required an OAuth2 access token, which had to be obtained using manual oauth2 client configuration and OAuth2 Grant Flows like Authorization Code Flow with PKCE.

All of that changed on Friday 13th January, 2023, when the new Service Accounts feature was released to the rapid release channel. That makes it available to all demo and sandbox environments and after the standard soak period of 2-4 weeks, Service Accounts should be released to all customer environments.

Once an environment supports service accounts, it benefits in the following ways:

  • Only one token to:
    • Access any AM (/am) API.
    • Access any IDM (/openidm) API.
  • Single API call JWT profile for OAuth 2.0 authorization grant flow (RFC7523) to get the one token to rule them all.
  • Set scopes on each service account to assign only necessary privileges.
  • Enhanced security as service accounts cannot extend their own privileges nor can they create new service accounts.

Now let’s dig into how to use this new option and how it helps with automation and building secure CI/CD pipelines.

Frodo + Service Accounts

The JWT profile is the mechanism by which clients using service accounts can obtain access tokens from Identity Cloud. The process involves creating and signing a JWT token using the private key saved when creating the service account, which isn’t for the faint of heart.

This is where Frodo comes into play. If you’ve been using the Frodo CLI or the Frodo Library to manage configuration in ForgeRock Identity Cloud, this latest Frodo release will make it easy to leverage the new Service Accounts feature without having to deal with the complexities of RFC7523 and the JWT profile or even creating service accounts through the UI.

Frodo CLI

Using the Frodo CLI is probably the simplest and most effective way to start experimenting with Service Accounts. Three ways to get started:

Connection profiles for daily CLI usage

For daily admin and development tasks, using the new frodo conn save command (see details under next bullet) is the easiest way to get going with service accounts. To migrate an existing connection profile to service accounts and automatically create a service account for your tenant admin, simply issue the following command:

% frodo conn save service-accounts
Connected to [alpha] as user
Created and added service account Frodo-SA-1673586189578 with id 99c04bba-7213-463b-9a27-ceafa8a95734 to profile.
Saved connection profile

Then validate your connection profile is using the new service account:

% frodo info service-accounts
Connected to [alpha] as service account Frodo-SA-1673586189578 [99c04bba-7213-463b-9a27-ceafa8a95734]

Host URL       │                                            
AM Version     │7.3.0-2022-10-SNAPSHOT Build 9a1793c301ef579705e59b66ce57587f553e915f (2022-December-13 10:05)
Subject (Type) │Frodo-SA-1673586189578 [99c04bba-7213-463b-9a27-ceafa8a95734] (Service Account)               
Deployment Type│cloud                                                                                         
Cookie Name    │e8b2bd07d5440d3                                                                               
Immutable      │false                                                                                         
Locked         │false                                                                                         
Region         │us-west1                                                                                      
Tier           │other                                                                                         

Bearer token:

Once you have verified that your service account works, go ahead and enable MFA for your tenant admin account!

CLI parameters

All commands support the following new options to use service accounts:

  • --sa-id <uuid> Service account’s uuid. If specified, must also include --sa-jwk-file.
  • --sa-jwk-file File containing the service account’s JSON Web Key (JWK). JWK must contain the private key! If specified, must also include --sa-id.

This is a great way to leverage the nice UI to create and manage service accounts and then use them with Frodo.

You can find the new service account editor in tenant settings. Frodo expects to have the following scopes to perform its supported functions:

  • fr:am:*
  • fr:idm:*
  • fr:idc:esv:*
New Service Account Wizard – Step 1

The New Service Account wizard makes it very easy to assign the required access. After you select Save, the wizard prompts to copy the new service account’s ID to the clipboard and to download the new service account’s key. Copying the ID is optional (you can retrieve it at any time). However, you must download the key in this step as it will not be available again and the service account cannot be used without this key:

New Service Account Wizard – Step 2

Now you are ready to use this service account with Frodo:

% frodo info --sa-id 1ffa3108-a5de-476a-977f-4432633100ce --sa-jwk-file ~/Downloads/cicd_privateKey.jwk       
Connected to [alpha] as service account cicd [1ffa3108-a5de-476a-977f-4432633100ce]

Host URL       │                                            
AM Version     │7.3.0-2022-10-SNAPSHOT Build 9a1793c301ef579705e59b66ce57587f553e915f (2022-December-13 10:05)
Subject (Type) │cicd [1ffa3108-a5de-476a-977f-4432633100ce] (Service Account)                                 
Deployment Type│cloud                                                                                         
Cookie Name    │e8b2bd07d5440d3                                                                               
Immutable      │false                                                                                         
Locked         │false                                                                                         
Region         │us-west1                                                                                      
Tier           │other                                                                                         

Bearer token:

Environment variables for CI/CD

For CI/CD pipelines, environment variables are preferable over command line parameters, because their values are not visible in system logs and process lists. Set the following environment variables in your CI/CD environment to instruct Frodo to use the specified service account:

  • FRODO_SA_ID: Service account’s uuid. If set, must also set FRODO_SA_JWK.
  • FRODO_SA_JWK: Service account’s JSON Web Key (JWK). JWK must contain private key! If set, must also set FRODO_SA_ID.

In the example below the environment variables are exported prior to running Frodo commands. In a real CI/CD pipeline environment these variables would be injected at runtime and JWK would be retrieved from a secret vault of some sort. But for testing, exporting in this will should demonstrate how it works well enough:

% export FRODO_SA_ID=1ffa3108-a5de-476a-977f-4432633100ce
% export FRODO_SA_JWK=$(cat ~/Downloads/cicd_privateKey.jwk)

Now that the environment is prepared, Frodo will pick up on those variables and leverage them:

% frodo info 
Connected to [alpha] as service account cicd [1ffa3108-a5de-476a-977f-4432633100ce]

Host URL       │                                            
AM Version     │7.3.0-2022-10-SNAPSHOT Build 9a1793c301ef579705e59b66ce57587f553e915f (2022-December-13 10:05)
Subject (Type) │cicd [1ffa3108-a5de-476a-977f-4432633100ce] (Service Account)                                 
Deployment Type│cloud                                                                                         
Cookie Name    │e8b2bd07d5440d3                                                                               
Immutable      │false                                                                                         
Locked         │false                                                                                         
Region         │us-west1                                                                                      
Tier           │other                                                                                         

Bearer token:

Frodo Library

Frodo Library is the engine that drives Frodo CLI. If command line interfaces are not the right approach for your use case, you can leverage Frodo Library and build your own interface, for example a REST interface or other.

Frodo Library can create service accounts with the required privileges or can use existing service accounts.

To create a service account use the new Jose helper and ServiceAccount API:

import { Jose, ServiceAccount } from '@rockcarver/frodo-lib';

const { createJwkRsa, createJwks, getJwkRsaPublic } = Jose;
const { createServiceAccount, isServiceAccountsFeatureAvailable } = ServiceAccount;

// check if the tenant supports service accounts
if (isServiceAccountsFeatureAvailable()) {
    const name = 'sa';
    const description = 'service account';
    const accountStatus = 'Active';
    const scopes = ['fr:am:*', 'fr:idm:*', 'fr:idc:esv:*'];
    // create a java web key (JWK) using RSA
    const jwk = await createJwkRsa();
    // extract only the public key as a JWK from the full JWK
    const publicJwk = await getJwkRsaPublic(jwk);
    // create a java wek key set (JWKS) from the public JWK
    const jwks = await createJwks(publicJwk);
    // create service account
    const payload = await ServiceAccount.createServiceAccount(
    // uuid of new service account if creation succeeded
    const saId = payload._id;

To instruct the library to use a service account set the following state variables:

import { state } from '@rockcarver/frodo-lib';

// setting both, id and jwk, instruct the library to use the service account

And finally, to perform any library function using the service account, get tokens first and then call any sequence of library functions, which will then all execute using the service account:

import { Authenticate, Info } from '@rockcarver/frodo-lib';

// get tokens
if (await Authenticate.getTokens()) {
  // get info about the connected environment
  const info = await Info.getInfo();
  // print the info object

Happy Pipeline Building!

Whether you choose the CLI or the library approach, the Frodo team and broader community is excited to support you. Please make sure to report challenges and voice requests for enhancement:

Leave a Reply

Your email address will not be published. Required fields are marked *