commit 52e7012b4126eba1bb36e810fe3eb8280f5b032a Author: Brandon Kalinowski Date: Mon Oct 28 15:01:27 2024 +0000 initial commit diff --git a/openfga-end.sh b/openfga-end.sh new file mode 100755 index 0000000..86918da --- /dev/null +++ b/openfga-end.sh @@ -0,0 +1,76 @@ +#!/bin/bash +# Source: https://raw.githubusercontent.com/rgl/incus-playground/349480b30d82ca1b468cb6e983988c7cb01343e3/provision-openfga.sh +set -euxo pipefail + +POSTGRES_FQDN="localhost" +OPENFGA_FQDN="localhost" + +# configure. +# see https://openfga.dev/docs/getting-started/setup-openfga/configure-openfga +# see https://github.com/openfga/openfga/blob/v1.5.2/internal/server/config/config.go#L189 +# see https://github.com/openfga/openfga/blob/v1.5.2/internal/server/config/config.go#L341 +cat >/opt/openfga/config.yaml </etc/systemd/system/openfga.service <~/.fga.yaml < ./openfga-incus.json diff --git a/provision-openfga.sh b/provision-openfga.sh new file mode 100755 index 0000000..c00b2c2 --- /dev/null +++ b/provision-openfga.sh @@ -0,0 +1,113 @@ +#!/bin/bash +# Source: https://raw.githubusercontent.com/rgl/incus-playground/349480b30d82ca1b468cb6e983988c7cb01343e3/provision-openfga.sh +set -euxo pipefail + +POSTGRES_FQDN="localhost" +OPENFGA_FQDN="localhost" + +# see https://github.com/openfga/openfga/releases +# renovate: datasource=github-releases depName=openfga/openfga +openfga_version='1.5.3' + +# create the openfga system user. +groupadd --system openfga || true +adduser \ + --system \ + --disabled-login \ + --no-create-home \ + --gecos '' \ + --ingroup openfga \ + --home /opt/openfga \ + openfga || true + +# download and install. +openfga_artifact_url="https://github.com/openfga/openfga/releases/download/v${openfga_version}/openfga_${openfga_version}_linux_amd64.tar.gz" +t="$(mktemp -q -d --suffix=.openfga)" +wget -qO "$t/openfga.tgz" "$openfga_artifact_url" +install -d "$t/dist" +tar xf "$t/openfga.tgz" -C "$t/dist" +rm -rf /opt/openfga +mv "$t/dist" /opt/openfga +chown -R root:root /opt/openfga +rm -rf "$t" + +# create the openfga role and database. +pushd / +sudo -sHu postgres psql -c "create role openfga login password 'abracadabra'" +sudo -sHu postgres createdb -E UTF8 -O openfga openfga >/dev/null +/opt/openfga/openfga migrate \ + --datastore-engine postgres \ + --datastore-uri "postgres://openfga:abracadabra@$POSTGRES_FQDN:5432/openfga" +sudo -sHu postgres psql -c '\du' +sudo -sHu postgres psql -l +popd + +# configure. +# see https://openfga.dev/docs/getting-started/setup-openfga/configure-openfga +# see https://github.com/openfga/openfga/blob/v1.5.2/internal/server/config/config.go#L189 +# see https://github.com/openfga/openfga/blob/v1.5.2/internal/server/config/config.go#L341 +cat >/opt/openfga/config.yaml </etc/systemd/system/openfga.service <