Resources /
Blog

Salesforce DevSecOps Pipeline: Build Security Into Every Deployment

Submit your details to get a book

9
Min Read
Resources /
Blog

Salesforce DevSecOps Pipeline: Build Security Into Every Deployment

Download

Submit your details to get a book

9
Min Read
Salesforce DevSecOps pipeline: a branching pipeline on a glowing pad, linked to code, clock and list tiles
Salesforce DevSecOps pipeline: a branching pipeline on a glowing pad, linked to code, clock and list tiles

A Salesforce DevSecOps pipeline runs security checks on every change before production: Code Analyzer scans, secrets checks, permission reviews and approvals. Each production deployment is validated, has a rollback plan and leaves evidence an auditor can sample later.

Below, we walk through how to wire those checks into a Salesforce DevOps release, one stage at a time. If you're after stages, roles and metrics instead, our Salesforce DevSecOps framework covers that bigger picture.

What does a secure Salesforce CI/CD pipeline check?

Each stage owns one or two checks, and every check should leave a record your release manager can point to. The table below lists each stage, its check and the evidence it leaves behind.

Pipeline stageSecurity checkEvidence it leaves
CommitSecrets detection before code is checked inScan result on the commit
Pull requestCode Analyzer scan and a peer review that can't be bypassedViolation counts, review approval
Permission reviewDiff of profiles and permission setsReviewer sign-off on access changes
ValidationCheck-only deployment with Apex tests in the target orgValidation ID, test and coverage results
ApprovalManual approval before productionApprover name and timestamp
Production deploymentQuick deployment of the validated set, with rollback on errorDeployment record, rollback plan
After releaseEvent and setup logsMetadataApiOpEventLog, Setup Audit Trail

The order of the stages can vary, but every check should run on every change, including the urgent Friday fix. Skipped checks tend to show up when an auditor samples your releases.

Why do Salesforce pipelines need their own security checks?

Salesforce's shared responsibility model says "customers are responsible for protecting their own data, configurations, and access rights." Most of those configurations reach production as metadata, so the deployment pipeline is the place to check them.

Code and configuration both carry risk here. Apex saved at API version 66.0 or earlier runs data operations in system mode by default, "with full CRUD access to objects and fields."

Classes saved at API version 67.0 or later run in user mode by default, so the API version on each class is worth a look in review. Salesforce's flow security guidance puts flows on the same list, since record-triggered flows run in system mode.

A pipeline built only for speed moves those changes faster, with no one checking them. NIST's Secure Software Development Framework (SP 800-218) notes that few development life cycle models "explicitly address software security in detail," so the practices have to be added.

How do you run Salesforce Code Analyzer in the pipeline?

Salesforce Code Analyzer is Salesforce's static code analysis tool for security vulnerabilities, performance issues and best practices. Its documentation says it "analyzes multiple languages including Apex, JavaScript, HTML, CSS, and Salesforce metadata such as Flows."

You can run it from the Salesforce CLI or through Salesforce's GitHub Action, and the two treat a failed scan very differently.

How you run itWhere it runsDoes it fail the build?Where results go
Salesforce CLIsf code-analyzer run on a laptop or build serverYes, with the --severity-threshold flag from the command reference, which exits non-zero at that severity or aboveA table in the terminal, or a file
GitHub ActionA step in your GitHub workflowNo, it "doesn't exit your GitHub workflow when it finds violations," so add a later step that fails on severity 1 or 2A workflow artifact and a job summary

If you'd rather focus a run on security, the reference shows how with --rule-selector "pmd:(Performance,Security):2". That example runs only the PMD rules tagged Security or Performance at severity 2.

Failing every pull request on old violations in a legacy codebase would stall the team. The Action can report violations in changed files only, so new code meets the standard while you clear the backlog on your own schedule.

Salesforce recommends that you integrate Code Analyzer into your CI/CD process to enforce the rules you define. Then the scan runs on every build, rather than whenever someone remembers before a release.

If you list a managed package on AgentExchange (formerly AppExchange), Salesforce says "You're also required to upload your Salesforce Code Analyzer scan reports" for security review. Our roundup of static code analysis tools compares other scanners.

Whichever scanner you pick, hold on to its output after each run. The SSDF's task PW.7.2 asks teams to "record and triage all discovered issues and recommended remediations" in their workflow or issue tracker.

Which Apex and Flow issues should the scan catch?

The Salesforce Secure Coding Guide covers the most common security issues Salesforce has found while auditing applications built on or integrated with its platform. A few of them belong in every pipeline review:

  • SOQL injection, where user input is joined into a dynamic query. Salesforce calls it less risky than SQL injection, though "the attacks are nearly identical."
  • Cross-site scripting, where an attacker can insert scripts or other active content into a page that other users view.
  • Missing CRUD and field-level security checks in Apex. Salesforce suggests WITH USER_MODE over WITH SECURITY_ENFORCED, which isn't allowed in AgentExchange packages.
  • Flows running with more access than they need. Screen flows must run in User Mode, and inputs marked "available for inputs" should be validated like any other user input.

A scanner won't catch every one of these on its own. Pair it with a human code review, which is what the SSDF's task PW.7.1 asks teams to plan for.

How do you keep secrets out of Salesforce metadata?

The Secure Coding Guide warns that storing secrets in source code isn't advisable "since anyone with access to the code can view the secrets in clear text." It also lists passwords, encryption keys and OAuth tokens as sensitive, and says to keep them out of debug logs.

For callouts, use named credentials instead of keys in Apex. A named credential holds the endpoint URL and its authentication, so Salesforce handles authentication and your code never sees the secret.

Named credentials also travel well between orgs. You can create one with the same name in each org, pointing at a different endpoint for development and production.

OWASP's Secrets Management Cheat Sheet suggests secrets scanning before a commit or pull request, in the IDE or with a pre-commit hook. It also recommends regular rotation, so a stolen credential only works for a short time.

The pipeline itself holds secrets too, such as the credentials it uses to deploy. Our guide to Salesforce API authentication covers how integrations should connect.

How should the pipeline handle permission changes?

Profiles and permission sets move as metadata, so an access change can ride along with an ordinary release. A permission set can only grant access, never deny it, which makes every added permission worth a second look.

Deploying one has a catch. Salesforce says that "when you deploy a permission set, you must include all of its metadata to avoid accidentally overwriting the permission set's contents."

Show the permission diff as its own review step, apart from the code review, so access changes can't hide inside a larger release. Our guides to Salesforce permission sets and permission sprawl cover what to look for.

Lock down who can change the pipeline as well. The SSDF's task PS.1.1 says to store all code, including configuration-as-code, "based on the principle of least privilege," and version control gives you that history.

Where do approvals and validation fit in Salesforce DevOps?

OWASP's CI/CD Security Cheat Sheet says to "Require manual approval and review before triggering production deployment." It also says pull request reviews should be required before merging, and that the review step shouldn't be bypassable.

Salesforce's Metadata API supports a two-step release. A deployment with checkOnly set to true runs a validation that verifies test results "but doesn't commit any changes."

A validated set can then go out as a quick deploy without rerunning tests, if it passed in the last 10 days. Coverage rules still apply: at least 75% org-wide coverage when all local tests run, and some coverage on Apex triggers.

The test level matters too. RunLocalTests is the default for production deployments that include Apex classes or triggers, while NoTestRun applies only to development environments such as sandboxes.

Put the approval between validation and the quick deployment. The approver then signs off on a package that has already passed its tests in the target org, and the deployment that follows is the same set they approved.

How do you secure sandboxes in the pipeline?

The SSDF's task PO.5.1 is to "Separate and protect each environment involved in software development." For Salesforce teams, the weak spot is usually production data copied into a sandbox for testing.

Salesforce Data Mask is a managed package that masks sensitive data in full and partial sandboxes. Trailhead says it masks data so it "is not replicated in a readable or recognizable way into another environment."

Masking should run before developers get access to a refreshed sandbox. Our posts on sandbox security and data masking go into the options.

How do you plan rollback for a Salesforce deployment?

The Metadata API's rollbackOnError option "must be set to true if you're deploying to a production org." With it on, any failure rolls back the whole deployment instead of saving the parts that worked.

That covers a deployment that fails. A deployment that succeeds and then causes trouble is a different case, and your plan for it should be to redeploy the previous version.

So each release needs to be kept. The SSDF's task PS.3.1 asks teams to "Securely archive the necessary files and supporting data" for each software release, which gives you a known-good version to restore.

What audit evidence should the pipeline keep?

The SSDF's task PO.3.3 is to "Configure tools to generate artifacts of their support of secure software development practices as defined by the organization." In a Salesforce pipeline, those are scan results, review approvals, validation IDs, test results and deployment records.

Salesforce logs some of this for you:

  • MetadataApiOpEventLog "stores details of Metadata API retrieval and deployment requests," from API version 62.0, for users with the View Event Log Object Data permission.
  • Setup Audit Trail lists who made each setup change and when. You can download the past 180 days, and after that the records are deleted.

Neither log records who approved a change or which tests passed. Those records have to come from the pipeline, as our audit trail compliance guide explains, and auditors for frameworks such as SOC 2 may sample them.

How Flosum supports a secure Salesforce pipeline

Flosum offers two hosting options: Flosum's cloud or your own cloud. Its Cloud Apps run on Flosum-managed AWS or on a virtual machine you own.

Flosum's DevOps Cloud App puts admin changes, developer code and AI-generated changes through the same version control, approvals and audit trail. Each change is validated against a dependency graph of your org, and one-click rollback reverses a release.

For test environments, Flosum's sandbox management creates Developer sandboxes with masked production data. Each new sandbox also comes with Flows disabled and access locked down, so test orgs start from a safe baseline.

FAQs

What is a Salesforce DevSecOps pipeline?

It's a release pipeline that runs security checks on every Salesforce change, from code scans to permission reviews and recorded approvals. NIST's SSDF is a common reference for which practices to build in.

Does Salesforce Code Analyzer fail a build by itself?

The CLI fails with a non-zero exit code when you set the --severity-threshold flag and a violation meets it, per the command reference. The GitHub Action doesn't stop the workflow, so you add a step that checks its violation counts.

Is Code Analyzer required for AgentExchange security review?

Yes, for managed packages. Salesforce says you must upload your Code Analyzer scan reports with your security review submission.

Which Apex tests run in a production deployment?

If you don't set a test level, RunLocalTests is the default for production when the deployment includes Apex classes or triggers. It runs every test in the org except those from installed managed and unlocked packages.

Does Salesforce Event Monitoring log deployments?

Yes. The MetadataApiOpEventLog object holds Metadata API retrieve and deploy requests, but it doesn't show the approver or the test results.

How long does Salesforce keep Setup Audit Trail history?

You can download 180 days of setup changes, and older records are deleted. Keep exports or pipeline records if your audit period runs longer.

Book a demo to see how Flosum's DevOps Cloud App adds approvals, rollback and audit trails to your Salesforce DevSecOps pipeline.

Table Of Contents
Author
Stay Up-to-Date
Get flosum.com news in your inbox.

Thank you for subscribing

Ship Salesforce changes faster
See how City and County of Denver cut routine deployments from up to 2 days to under 15 minutes.
Free to start  |  No credit card required