Skip to content

Commit 617e1d1

Browse files
committed
Staging megamerge
4 parents d6e926c + f17b8d5 + 4c98227 + cf7a2f5 commit 617e1d1

63 files changed

Lines changed: 1559 additions & 190 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ jobs:
249249
# Start share and it's dependencies in the background
250250
docker compose -f docker/docker-compose.yml up --wait
251251
252+
252253
# Run the transcript tests
253254
zsh ./transcripts/run-transcripts.zsh
254255

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ docker_staging_push: $(docker_server_release)
5353

5454
serve: $(installed_share)
5555
trap 'docker compose -f docker/docker-compose.yml down' EXIT INT TERM
56-
docker compose -f docker/docker-compose.yml up postgres redis &
57-
while ! ( pg_isready --host localhost -U postgres -p 5432 && redis-cli -p 6379 ping) do \
56+
docker compose -f docker/docker-compose.yml up postgres redis vault &
57+
while ! ( pg_isready --host localhost -U postgres -p 5432 && redis-cli -p 6379 ping && VAULT_ADDR=http://localhost:8200 vault status) do \
5858
echo "Waiting for postgres and redis..."; \
5959
sleep 1; \
6060
done;

app/Env.hs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import Hasql.Pool qualified as Pool
2626
import Hasql.Pool.Config qualified as Pool
2727
import Network.URI (parseURI)
2828
import Servant.API qualified as Servant
29+
import Servant.Client qualified as ServantClient
2930
import System.Environment (lookupEnv)
3031
import System.Exit
3132
import System.Log.FastLogger qualified as FL
@@ -34,6 +35,9 @@ import System.Log.Raven.Transport.HttpConduit qualified as Sentry
3435
import System.Log.Raven.Types qualified as Sentry
3536
import Unison.Runtime.Interface as RT
3637
import Data.Time.Clock qualified as Time
38+
import Network.HTTP.Client.TLS qualified as TLS
39+
import Network.HTTP.Client qualified as HTTPClient
40+
import Vault qualified
3741

3842
withEnv :: (Env () -> IO a) -> IO a
3943
withEnv action = do
@@ -114,6 +118,31 @@ withEnv action = do
114118
pgConnectionPool <- Pool.acquire pgSettings
115119
timeCache <- FL.newTimeCache FL.simpleTimeFormat -- E.g. 05/Sep/2023:13:23:56 -0700
116120
sandboxedRuntime <- RT.startRuntime True RT.Persistent "share"
121+
122+
-- Vault setup
123+
unproxiedHttpClient <- TLS.newTlsManager
124+
vaultHost <- fromEnv "VAULT_HOST" parseBaseUrl
125+
userSecretsVaultMount <- fromEnv "USER_SECRETS_VAULT_MOUNT" ((fmap . fmap) Vault.SecretMount . nonEmptyTextParser "USER_SECRETS_VAULT_MOUNT")
126+
shareVaultToken <- fromEnv "VAULT_TOKEN" ((fmap . fmap) Vault.VaultToken . nonEmptyTextParser "VAULT_TOKEN")
127+
let vaultClientEnv = ServantClient.mkClientEnv unproxiedHttpClient vaultHost
128+
129+
130+
131+
proxiedHttpClient <- do
132+
if Deployment.onLocal
133+
then TLS.newTlsManager
134+
else do
135+
httpProxyHost <- fromEnv "SHARE_PROXY_HOST" ((fmap . fmap) Text.encodeUtf8 . nonEmptyTextParser "SHARE_PROXY_HOST")
136+
httpProxyPort <- fromEnv "SHARE_PROXY_PORT" (pure . maybeToEither "Invalid SHARE_PROXY_PORT" . readMaybe)
137+
138+
-- http proxy setup
139+
let proxyOverride = HTTPClient.useProxy (HTTPClient.Proxy{HTTPClient.proxyHost = httpProxyHost, HTTPClient.proxyPort = httpProxyPort})
140+
let proxiedManagerSettings =
141+
TLS.tlsManagerSettings
142+
& HTTPClient.managerSetProxy proxyOverride
143+
TLS.newTlsManagerWith proxiedManagerSettings
144+
145+
-- Logging setup
117146
let ctx = ()
118147
-- We use a zero-width-space to separate log-lines on ingestion, this allows us to use newlines for
119148
-- formatting, but without affecting log-grouping.
@@ -122,6 +151,15 @@ withEnv action = do
122151
action $ Env {logger = (logger . (\msg -> zeroWidthSpace <> msg <> "\n")), ..}
123152
where
124153
readPort p = pure $ maybeToRight "SHARE_PORT was not a number" (readMaybe p)
154+
nonEmptyTextParser :: Text -> String -> IO (Either String Text)
155+
nonEmptyTextParser varName = \case
156+
"" -> pure . Left . Text.unpack $ "Expected a value for env var " <> varName <> ", but got an empty string"
157+
str -> pure . Right $ Text.pack str
158+
159+
parseBaseUrl :: String -> IO (Either String ServantClient.BaseUrl)
160+
parseBaseUrl str = do
161+
u <- ServantClient.parseBaseUrl str
162+
pure $ Right u
125163

126164
fromEnv :: String -> (String -> IO (Either String a)) -> IO a
127165
fromEnv var from = do

docker/docker-compose.yml

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,37 @@ services:
3232
ports:
3333
- "6379:6379"
3434

35+
vault:
36+
image: 'hashicorp/vault:1.19'
37+
container_name: vault
38+
healthcheck:
39+
test: ["CMD", "vault", "status"]
40+
interval: 3s
41+
timeout: 10s
42+
retries: 3
43+
ports:
44+
- "8200:8200"
45+
environment:
46+
VAULT_DEV_ROOT_TOKEN_ID: "sekrit"
47+
VAULT_KV_V1_MOUNT_PATH: "secret"
48+
VAULT_ADDR: "http://127.0.0.1:8200"
49+
cap_add:
50+
- IPC_LOCK
51+
# # Use kv version 1
52+
# command: server -dev
53+
3554
share:
3655
image: share-api
3756
container_name: share-api
3857
depends_on:
39-
- redis
40-
- postgres
58+
redis:
59+
condition: service_healthy
60+
postgres:
61+
condition: service_healthy
62+
vault:
63+
condition: service_healthy
64+
http-echo:
65+
condition: service_started
4166
healthcheck:
4267
test: ["CMD", "curl", "-f", "http://localhost:5424/health"]
4368
interval: 3s
@@ -53,10 +78,10 @@ services:
5378
- SHARE_SERVER_PORT=5424
5479
- SHARE_REDIS=redis://redis:6379
5580
- SHARE_POSTGRES=postgresql://postgres:sekrit@postgres:5432
56-
- SHARE_HMAC_KEY=hmac-key-test-key-test-key-test-
57-
- SHARE_EDDSA_KEY=eddsa-key-test-key-test-key-test
5881
- SHARE_POSTGRES_CONN_TTL=30
5982
- SHARE_POSTGRES_CONN_MAX=10
83+
- SHARE_HMAC_KEY=hmac-key-test-key-test-key-test-
84+
- SHARE_EDDSA_KEY=eddsa-key-test-key-test-key-test
6085
- SHARE_SHARE_UI_ORIGIN=http://localhost:1234
6186
- SHARE_CLOUD_UI_ORIGIN=http://localhost:5678
6287
- SHARE_HOMEPAGE_ORIGIN=http://localhost:1111
@@ -65,6 +90,9 @@ services:
6590
- SHARE_COMMIT=dev
6691
- SHARE_MAX_PARALLELISM_PER_DOWNLOAD_REQUEST=1
6792
- SHARE_MAX_PARALLELISM_PER_UPLOAD_REQUEST=5
93+
- VAULT_HOST=http://vault:8200/v1
94+
- VAULT_TOKEN=sekrit
95+
- USER_SECRETS_VAULT_MOUNT=secret # A default mount in dev vault
6896
- SHARE_ZENDESK_API_USER=invaliduser@example.com
6997
- SHARE_ZENDESK_API_TOKEN=bad-password
7098
- SHARE_GITHUB_CLIENTID=invalid
@@ -73,6 +101,17 @@ services:
73101
links:
74102
- redis
75103
- postgres
104+
- vault
105+
- http-echo
106+
107+
http-echo:
108+
image: 'mendhak/http-https-echo:36'
109+
container_name: http-echo
110+
environment:
111+
HTTP_PORT: 9999
112+
ECHO_BACK_TO_CLIENT: "false"
113+
ports:
114+
- "9999:9999"
76115

77116
# volumes:
78117
# postgresVolume:

local.env

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ export SHARE_LOG_LEVEL="DEBUG"
1919
export SHARE_COMMIT="dev"
2020
export SHARE_MAX_PARALLELISM_PER_DOWNLOAD_REQUEST="1"
2121
export SHARE_MAX_PARALLELISM_PER_UPLOAD_REQUEST="5"
22+
export VAULT_HOST="http://localhost:8200/v1"
23+
export VAULT_TOKEN="sekrit"
24+
export USER_SECRETS_VAULT_MOUNT="secret" # A default mount in dev vault
25+
# Proxies aren't used locally, but are required in staging and production
26+
# export SHARE_PROXY_HOST="http://localhost"
27+
# export SHARE_PROXY_PORT="9999"
2228

2329
# Placeholders, these features don't work on localhost.
2430
export SHARE_ZENDESK_API_USER="invaliduser@example.com"

share-api.cabal

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ library
3636
Share.BackgroundJobs.Search.DefinitionSync.Types
3737
Share.BackgroundJobs.SerializedEntitiesMigration.Queries
3838
Share.BackgroundJobs.SerializedEntitiesMigration.Worker
39+
Share.BackgroundJobs.Webhooks.Queries
40+
Share.BackgroundJobs.Webhooks.Types
41+
Share.BackgroundJobs.Webhooks.Worker
3942
Share.BackgroundJobs.Workers
4043
Share.Branch
4144
Share.Codebase
@@ -50,8 +53,10 @@ library
5053
Share.NamespaceDiffs
5154
Share.Notifications.API
5255
Share.Notifications.Impl
56+
Share.Notifications.Ops
5357
Share.Notifications.Queries
5458
Share.Notifications.Types
59+
Share.Notifications.Webhooks.Secrets
5560
Share.Postgres
5661
Share.Postgres.Admin
5762
Share.Postgres.Authorization.Queries

share-auth/src/Share/JWT/Types.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ instance (Applicative m) => JWT.VerificationKeyStore m (JWT.JWSHeader ()) payloa
233233

234234
-- | A newtype for JWTs which provides the appropriate encoding/decoding instances.
235235
newtype JWTParam = JWTParam JWT.SignedJWT
236+
deriving newtype (Eq)
236237
deriving (Show) via (Censored JWTParam)
237238

238239
instance ToHttpApiData JWTParam where

share-auth/src/Share/OAuth/Session.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,10 @@ data LoginRequest
261261
deriving anyclass (ToJSON, FromJSON)
262262
deriving (Binary) via JSONBinary LoginRequest
263263

264-
-- | Sessions expire in 30 days
264+
-- | Sessions expire in 1 year
265265
sessionTTL :: NominalDiffTime
266266
sessionTTL =
267-
(30 * nominalDay)
267+
(365 * nominalDay)
268268

269269
createSession :: (MonadIO m) => URI -> Set URI -> UserId -> m Session
270270
createSession sessionIssuer sessionAudience sessionUserId = do

share-utils/package.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,15 @@ dependencies:
6969
- cryptonite
7070
- http-api-data
7171
- http-types
72+
- http-media
7273
- jose
7374
- memory
7475
- network-uri
7576
- pretty-simple
7677
- random
7778
- servant-auth
7879
- servant-server
80+
- servant-client
7981
- text
8082
- time
8183
- uuid

share-utils/share-utils.cabal

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ library
3333
Share.Utils.Servant.Cookies
3434
Share.Utils.Show
3535
Share.Utils.URI
36+
Vault
3637
other-modules:
3738
Paths_share_utils
3839
hs-source-dirs:
@@ -81,6 +82,7 @@ library
8182
, hasql
8283
, hasql-interpolate
8384
, http-api-data
85+
, http-media
8486
, http-types
8587
, jose
8688
, lens
@@ -89,6 +91,7 @@ library
8991
, pretty-simple
9092
, random
9193
, servant-auth
94+
, servant-client
9295
, servant-server
9396
, text
9497
, time

0 commit comments

Comments
 (0)