Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Render 6 min read Case study mediumAdept

How Render Enforces Access Controls with Go Generics

Render enforces role-based access control at compile time by wrapping domain objects like Project in opaque types (AuthorizedProject) that can only be constructed through a permission-checking function. This guarantees model-layer code never runs without an authorization check. Go generics go further: each permission is a distinct type parameter, so passing an object authorized for "update" into a "delete" method is a type error, though tooling gaps around generics have kept that final step from being merged. Rare bootstrapping cases use an explicitly named UnsafeAuthorize() that gets extra review. The tradeoff is more code per new permission, but the compiler yields a complete list of codepaths to update, which caught real security holes before launch.

Related posts

  • Making code-generation in Go more powerful with generics

    incident.io mediumAdept

    Combining Go generics with code generation gives type-safe partial structs: a generic Partial[T] tracks which fields are set alongside a subject value, enabling safe partial updates through a Gorm wrapper that avoids zero-value overwrites and race conditions. Generated per-type builders (UserBuilder.Name(...)) remove typo-prone field-name strings and let the compiler reject setters from the wrong base type. Generated matchers wrap Gomega's gstruct so test assertions are type-checked, which catches field type changes such as null.String to string at compile time. The design principle is to put complex logic in readable generic code and generate only simple boilerplate. The library is open-sourced as incident-io/partial.

  • Modelling Authorization for a Social Network with Postgres RLS and Drizzle ORM

    Neon mediumAdept

    Postgres Row-Level Security can express the full authorization model for a Twitter-like social network, defined with Drizzle ORM's crudPolicy and pgPolicy helpers and the pg_session_jwt extension's auth.user_id(). Profiles, posts and comments get simple policies: public reads, owner-only writes. Private chats need more care: participants can only see other participants of their own chats, a self-referential rule RLS can't express without recursion errors, so it lives in a view made read-only by adding DISTINCT. Takeaways are that raw-SQL RLS is error-prone, testing policies is hard, schemas exposed to the frontend need careful design beyond policies (e.g. unique constraints), and this work shouldn't be trusted to an LLM.

  • How we built a custom permissions DSL at Figma

    Figma mediumAdept

    Figma replaced a sprawling Ruby `has_access?` permissions function with a custom, JSON-serializable permissions DSL and a cross-platform policy engine, inspired by AWS IAM policies. Each policy declares a resource type, an allow/deny effect, granular permissions and boolean conditions written as ExpressionDef triples that reference data fields such as `file.deleted_at`. Because policies are pure data, the same rules run in both the Ruby/Sinatra backend and the TypeScript LiveGraph realtime layer, and data dependencies can be extracted statically. That separation decouples policy logic from data loading, letting rules be written and debugged independently and reducing database load from permission checks, which had been about 20% of total load.

  • Rolling out Roles

    incident.io mediumAdept

    incident.io added role-based access control by mapping a fixed set of customer-facing roles (owner, admin, etc.) to granular internal scopes. A variadic getIdentity(ctx, requiredScopes...) check in Go puts each API's permission behind a one-line change, and generated type-safe scope enums let the TypeScript frontend gate UI such as a GatedButton. Rollout used a per-organization enforcement timestamp with a March 1st deadline and owner opt-in. Initial owners were the original installers and admins were inferred from past product usage, with owners prompted to review both.

  • Higher-level CRUD Abstraction for Postgres RLS

    Neon mediumAdept

    Postgres Row-Level Security requires separate USING and WITH CHECK policies per operation, which gets repetitive for CRUD apps. Neon's Drizzle ORM helper `crudPolicy` takes a role plus `read` and `modify` expressions (true, false, a SQL expression, or null to skip) and generates the select, insert, update and delete policies. A companion `authUid` helper ties pg_session_jwt's `auth.user_id()` to a table column. The post shows the raw SQL for a todos table next to the equivalent concise Drizzle schema. The functionality has since moved into the Neon Data API.

The quest for software engineering knowledge.

Look:
Layout: