From a4b5716d159cb35f99d5291c1951f140643c0c68 Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Sat, 26 Feb 2022 13:10:37 -0500 Subject: Stop tracking the built site! --- site/code/commit-messages/index.html | 177 ----------------- site/code/configuring-browser-apps/index.html | 267 -------------------------- site/code/index.html | 192 ------------------ site/code/users-rolegraph-privs/index.html | 244 ----------------------- 4 files changed, 880 deletions(-) delete mode 100644 site/code/commit-messages/index.html delete mode 100644 site/code/configuring-browser-apps/index.html delete mode 100644 site/code/index.html delete mode 100644 site/code/users-rolegraph-privs/index.html (limited to 'site/code') diff --git a/site/code/commit-messages/index.html b/site/code/commit-messages/index.html deleted file mode 100644 index 2692dc0..0000000 --- a/site/code/commit-messages/index.html +++ /dev/null @@ -1,177 +0,0 @@ - - - - - - - - - - - Writing Good Commit Messages - The Grimoire - - - - - - - - - - - - - - - - - -
- -
- -

Writing Good Commit Messages

-

Rule zero: “good” is defined by the standards of the project you're on. Have a look at what the existing messages look like, and try to emulate that first before doing anything else.

-

Having said that, here are some principles I've found helpful and broadly applicable.

-
    -
  • -

    Treat the first line of the message as a one-sentence summary. Most SCM systems have an “overview” command that shows shortened commit messages in bulk, so making the very beginning of the message meaningful helps make those modes more useful for finding specific commits. It's okay for this to be a “what” description if the rest of the message is a “why” description.

    -
  • -
  • -

    Fill out the rest of the message with prose outlining why you made the change. Don't reiterate the contents of the change in great detail if you can avoid it: anyone who needs that can read the diff themselves, or reach out to ask for help understanding the change. A good rationale sets context for the problem being solved and addresses the ways the proposed change alters that context.

    -
  • -
  • -

    If you use an issue tracker (and you should), include whatever issue-linking notes it supports right at the start of the message, where it'll be visible even in summarized commit logs. If your tracker has absurdly long issue-linking syntax, or doesn't support issue links in commits at all, include a short issue identifier at the front of the message and put the long part somewhere out of the way, such as on a line of its own at the end of the message.

    -
  • -
  • -

    If you need rich commit messages (links, lists, and so on), pick one markup language and stick with it. It'll be easier to write useful commit formatters if you only have to deal with one syntax, rather than four. Personally, I use Markdown when I can, or a reduced subset of Markdown, as it's something most developers I interact with will be at least passing familiar with.

    -
  • -
-
- - - - - - - - - - diff --git a/site/code/configuring-browser-apps/index.html b/site/code/configuring-browser-apps/index.html deleted file mode 100644 index de2abd7..0000000 --- a/site/code/configuring-browser-apps/index.html +++ /dev/null @@ -1,267 +0,0 @@ - - - - - - - - - - - Configuring Browser Apps - The Grimoire - - - - - - - - - - - - - - - - - -
- -
- -

Configuring Browser Apps

-

I've found myself in he unexpected situation of having to write a lot of -browser apps/single page apps this year. I have some thoughts on configuration.

-

Why Bother

-
    -
  • Centralize environment-dependent facts to simplify management & testing
  • -
  • -

    Make it easy to manage app secrets.

    -

    @wlonk adds:

    -
    -

    “Secrets”? What this means in a browser app is a bit different.

    -
    -

    Which is unpleasantly true. In a freestanding browser app, a “secret” is only as secret as your users and their network connections choose to make it, i.e., not very secret at all. Maybe that should read “make it easy to manage app tokens and identities,” instead.

    -
  • -
  • -

    Keep config data & API tokens out of app's source control

    -
  • -
  • Integration point for external config sources (Aerobatic, Heroku, etc)
  • -
  • The forces described in 12 Factor App: Dependencies and, to a lesser extent, 12 Factor App: Configuration apply just as well to web client apps as they do to freestanding services.
  • -
-

What Gets Configured

-

Yes:

-
    -
  • Base URLs of backend services
  • -
  • Tokens and client IDs for various APIs
  • -
-

No:

-
    -
  • “Environments” (sorry, Ember folks - I know Ember thought this through carefully, but whole-env configs make it easy to miss settings in prod or test, and encourage patterns like “all devs use the same backends”)
  • -
-

Delivering Configuration

-

There are a few ways to get configuration into the app.

-

Globals

-
<head>
-    <script>window.appConfig = {
-        "FOO_URL": "https://foo.example.com/",
-        "FOO_TOKEN": "my-super-secret-token"
-    };</script>
-    <script src="/your/app.js"></script>
-</head>
-
- -
    -
  • Easy to consume: it's just globals, so window.appConfig.foo will read them.
      -
    • This requires some discipline to use well.
    • -
    -
  • -
  • Have to generate a script to set them.
      -
    • This can be a <script>window.appConfig = {some json}</script> tag or a standalone config script loaded with <script src="/config.js">
    • -
    • Generating config scripts sets a minimum level of complexity for the deployment process: you either need a server to generate the script at request time, or a preprocessing step at deployment time.
    • -
    • -

      It's code generation, which is easy to do badly. I had originally proposed using JSON.stringify to generate a Javascript object literal, but this fails for any config values with </script> in them. That may be an unlikely edge case, but that only makes it a nastier trap for administrators.

      -

      There are more edge cases. I strongly suspect that a hazard-free implementation requires a full-blown JS source generator. I had a look at building something out of escodegen and estemplate, but

      -
        -
      1. -

        escodegen's node version doesn't generate browser-safe code, so string literals with </script> or </head> in them still break the page, and

        -
      2. -
      3. -

        converting javascript values into parse trees to feed to estemplate is some seriously tedious code.

        -
      4. -
      -
    • -
    -
  • -
- -
<head>
-    <link rel="foo-url" href="https://foo.example.com/">
-    <script src="/your/app.js" data-foo-token="my-super-secret-token"></script>
-</head>
-
- -
    -
  • Flat values only. This is probably a good thing in the grand, since flat configurations are easier to reason about and much easier to document, but it makes namespacing trickier than it needs to be for groups of related config values (URL + token for a single service, for example).
  • -
  • Have to generate the DOM to set them.
      -
    • This is only practical given server-side templates or DOM rendering. You can't do this with bare nginx, unless you pre-generate pages at deployment time.
    • -
    -
  • -
-

Config API Endpoint

-
fetch('/config') /* {"FOO_URL": …, "FOO_TOKEN": …} */
-    .then(response => response.json())
-    .then(json => someConfigurableService);
-
- -
    -
  • Works even with “dumb” servers (nginx, CloudFront) as the endpoint can be a generated JSON file on disk. If you can generate files, you can generate a JSON endpoint.
  • -
  • Requires an additional request to fetch the configuration, and logic for injecting config data into all the relevant configurable places in the code.
      -
    • This request can't happen until all the app code has loaded.
    • -
    • It's very tempting to write the config to a global. This produces some hilarious race conditions.
    • -
    -
  • -
-

Cookies

-

See for example clientconfig:

-
var config = require('clientconfig');
-
- -
    -
  • Easy to consume given the right tools; tricky to do right from scratch.
  • -
  • Requires server-side support to send the correct cookie. Some servers will allow you to generate the right cookie once and store it in a config file; others will need custom logic, which means (effectively) you need an app server.
  • -
  • Cookies persist and get re-sent on subsequent requests, even if the server stops delivering config cookies. Client code has to manage the cookie lifecycle carefully (clientconfig does this automatically)
  • -
  • Size limits constrain how much configuration you can do.
  • -
-
- - - - - - - - - - diff --git a/site/code/index.html b/site/code/index.html deleted file mode 100644 index f26b2dd..0000000 --- a/site/code/index.html +++ /dev/null @@ -1,192 +0,0 @@ - - - - - - - - - - - The Grimoire - - - - - - - - - - - - - - - - - -
-
-
- -

Code

-

Pieces of code and code-adjacent work, with or without exposition, that don't quite fit into the library ecosystem, but which I enjoyed writing.

- -

I also maintain a Github account for more substantial projects.

-
- - - - - - - - - - - - diff --git a/site/code/users-rolegraph-privs/index.html b/site/code/users-rolegraph-privs/index.html deleted file mode 100644 index 386be98..0000000 --- a/site/code/users-rolegraph-privs/index.html +++ /dev/null @@ -1,244 +0,0 @@ - - - - - - - - - - - A Users, Roles & Privileges Scheme Using Graphs - The Grimoire - - - - - - - - - - - - - - - - - -
- -
- -

A Users, Roles & Privileges Scheme Using Graphs

-

The basic elements:

-
    -
  • Every agent that can interact with a system is represented by a user.
  • -
  • Every capability the system has is authorized by a distinct privilege.
  • -
  • Each user has a list of zero or more roles.
      -
    • Roles can imply further roles. This relationship is transitive: if role A implies role B, then a member of role A is a member of role B; if role B also implies role C, then a member of role A is also a member of role C. It helps if the resulting role graph is acyclic, but it's not necessary.
    • -
    • Roles can grant privileges.
    • -
    -
  • -
-

A user's privileges are the union of the privileges granted by the transitive closure of their roles.

-
create table "user" (
-    username varchar
-        primary key
-    -- credentials &c
-);
-
-create table role (
-    name varchar
-        primary key
-);
-
-create table role_member (
-    role varchar
-        not null
-        references role,
-    member varchar
-        not null
-        references "user",
-    primary key (role, member)
-);
-
-create table role_implies (
-    role varchar
-        not null
-        references role,
-    implied_role varchar
-        not null
-);
-
-create table privilege (
-    privilege varchar
-        primary key
-);
-
-create table role_grants (
-    role varchar
-        not null
-        references role,
-    privilege varchar
-        not null
-        references privilege,
-    primary key (role, privilege)
-);
-
- -

If your database supports recursive CTEs, this schema can be queried in one shot, since we can have the database do all the graph-walking along roles:

-
with recursive user_roles (role) AS (
-    select
-        role
-    from
-        role_member
-    where
-        member = 'SOME USERNAME'
-    union
-    select
-        implied_role as role
-    from
-        user_roles
-        join role_implies on
-            user_roles.role = role_implies.role
-)
-select distinct
-    role_grants.privilege as privilege
-from
-    user_roles
-    join role_grants on
-        user_roles.role = role_grants.role
-order by privilege;
-
- -

If not, you'll need to pull the entire graph into memory and manipulate it there: this schema doesn't give you any easy handles to identify only the roles transitively included in the role of interest, and repeatedly querying for each step of the graph requires an IO roundtrip at each step, burning whole milliseconds along the way.

-

Realistic use cases should have fairly simple graphs: elemental privileges are grouped into concrete roles, which are in turn grouped into abstracted roles (by department, for example), which are in turn granted to users. If the average user is in tens of roles and has hundreds of privileges, the entire dataset fits in memory, and PostgreSQL performs well. In PostgreSQL, the above schema handles ~10k privileges and ~10k roles with randomly-generated graph relationships in around 100ms on my laptop, which is pretty slow but not intolerable. Perverse cases (interconnected total subgraphs, deeply-nested linear graphs) can take absurd time but do not reflect any likely permissions scheme.

-
- - - - - - - - - - -- cgit v1.2.3