Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/pass send push messages #48

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
140a4b1
feat: pass bootstrap (#21)
tobiaszheller Jan 3, 2024
aa3f53f
chore: organise imports
krzysztofdrys Jan 4, 2024
1413d10
Develop/pass deploy (#22)
krzysztofdrys Jan 8, 2024
dbd4245
initial version of pairing and proxy (#23)
tobiaszheller Jan 12, 2024
17fb204
feat(pass): tokens (#24)
krzysztofdrys Jan 19, 2024
417d7d2
feat: use Sec-WebSocket-Protocol to pass auth on ws (#26)
tobiaszheller Jan 21, 2024
c00c8a4
feat: e2e tests for pass (#28)
krzysztofdrys Jan 22, 2024
782e771
feat: connect pass with kms (#29)
tobiaszheller Jan 24, 2024
ce476fe
fix: pass region from env
tobiaszheller Jan 24, 2024
a0ebcb2
use shared config state
tobiaszheller Jan 25, 2024
8720f1c
fix: deployment family
tobiaszheller Jan 25, 2024
7eeedb3
fix: deployment task arn
tobiaszheller Jan 25, 2024
cab30f7
feat: configurable tests (#30)
tobiaszheller Feb 16, 2024
4c16a1e
fix issues with README and contributing guidelines (#33)
KobeW50 Mar 8, 2024
34d87a8
feat/sync endpoint (#34)
krzysztofdrys Apr 5, 2024
d1176fd
fix(pass): increase max message size (#41)
krzysztofdrys Apr 9, 2024
1478cc5
develop/pass fix retry (#43)
krzysztofdrys Apr 18, 2024
c36c698
Merge branch 'main' into develop/pass-sync-master
tobiaszheller Apr 27, 2024
919d2f2
fix: pass tests
tobiaszheller Apr 27, 2024
963533d
Merge pull request #44 from twofas/develop/pass-sync-master
tobiaszheller May 3, 2024
a8317c1
feat: connect firebase sdk
tobiaszheller May 6, 2024
6a7d36b
Merge pull request #45 from twofas/feat/connect-firebase-sdk
tobiaszheller May 6, 2024
bc22800
feat/rework pass sync (#47)
krzysztofdrys May 7, 2024
5377ec0
feat: send push to mobile
krzysztofdrys May 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,10 @@ WEBSOCKET_LISTEN_ADDR=:8081
SECURITY_RATE_LIMIT_IP=1000
SECURITY_RATE_LIMIT_BE=100
SECURITY_RATE_LIMIT_MOBILE=100

PASS_ADDR=:8082
FAKE_MOBILE_PUSH=true

AWS_ACCESS_KEY_ID=test
AWS_SECRET_ACCESS_KEY=test
AWS_ENDPOINT="http://localhost:4566"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ licenses-errors

data/
.env.testing

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ tests-e2e: ## run end to end tests
go test ./e2e-tests/mobile/... -count=1
go test ./e2e-tests/support/... -count=1
go test ./e2e-tests/system/... -count=1

PASS_ADDR="localhost:8088" go test ./e2e-tests/pass/... -count=1

vendor-licenses: ## report vendor licenses
go-licenses report ./cmd/api --template licenses.tpl > licenses.json 2> licenses-errors
25 changes: 25 additions & 0 deletions cmd/pass/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package main

import (
"github.com/kelseyhightower/envconfig"

"github.com/twofas/2fas-server/config"
"github.com/twofas/2fas-server/internal/common/logging"
"github.com/twofas/2fas-server/internal/pass"
)

func main() {
logging.Init(logging.Fields{"service_name": "pass"})

var cfg config.PassConfig
err := envconfig.Process("", &cfg)
if err != nil {
logging.Fatal(err.Error())
}

server := pass.NewServer(cfg)

if err := server.Run(); err != nil {
logging.Fatal(err.Error())
}
}
13 changes: 13 additions & 0 deletions config/pass_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package config

import "time"

type PassConfig struct {
Addr string `envconfig:"PASS_ADDR" default:":8082"`
KMSKeyID string `envconfig:"KMS_KEY_ID" default:"alias/pass_service_signing_key"`
AWSEndpoint string `envconfig:"AWS_ENDPOINT" default:""`
AWSRegion string `envconfig:"AWS_REGION" default:"us-east-2"`
FirebaseServiceAccount string `envconfig:"FIREBASE_SA"`
FakeMobilePush bool `envconfig:"FAKE_MOBILE_PUSH" default:"false"`
PairingRequestTokenValidityDuration time.Duration `envconfig:"PAIRING_REQUEST_TOKEN_VALIDITY_DURATION" default:"8765h"` // 1 year
}
9 changes: 9 additions & 0 deletions deployments/pass/appspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 0.0
Resources:
- TargetService:
Type: AWS::ECS::Service
Properties:
TaskDefinition: <TASK_DEFINITION>
LoadBalancerInfo:
ContainerName: "2fas-pass"
ContainerPort: 8082
38 changes: 38 additions & 0 deletions deployments/pass/buildspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
version: 0.2

env:
secrets-manager:
DOCKERHUB_USERNAME: hub.docker.com:username
DOCKERHUB_PASS: hub.docker.com:password

phases:
pre_build:
commands:
- IMAGE_TAG=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
- REPOSITORY_URI=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME
- echo Logging in to Docker HUB to avoid rate limit
- echo "$DOCKERHUB_PASS" | docker login --username $DOCKERHUB_USERNAME --password-stdin
- echo Logging in to Amazon ECR
- aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com

build:
commands:
- echo Build started on `date`
- echo Building the Docker image
- docker build -f docker/pass/Dockerfile -t $REPOSITORY_URI:latest .
- docker tag $REPOSITORY_URI:latest $REPOSITORY_URI:$IMAGE_TAG

post_build:
commands:
- echo Build completed on `date`
- echo Pushing the Docker images latest, $IMAGE_TAG
- docker push $REPOSITORY_URI:latest
- docker push $REPOSITORY_URI:$IMAGE_TAG
- sed -i 's/<AWS_ACCOUNT_ID>/'$AWS_ACCOUNT_ID'/g' deployments/pass/taskdef.json
- sed -i 's/<IMAGE_NAME>/'$AWS_ACCOUNT_ID'\.dkr\.ecr\.'$AWS_DEFAULT_REGION'\.amazonaws.com\/'$IMAGE_REPO_NAME'\:'$IMAGE_TAG'/g' deployments/pass/taskdef.json

artifacts:
files:
- imageDetail.json
- deployments/pass/appspec.yml
- deployments/pass/taskdef.json
45 changes: 45 additions & 0 deletions deployments/pass/taskdef.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"executionRoleArn": "arn:aws:iam::<AWS_ACCOUNT_ID>:role/2fas-pass_ecsTaskExecutionRole",
"taskRoleArn": "arn:aws:iam::<AWS_ACCOUNT_ID>:role/2fas-pass_ecsTaskRole",
"containerDefinitions": [
{
"name": "2fas-pass",
"image": "<IMAGE_NAME>",
"essential": true,
"portMappings": [
{
"hostPort": 8082,
"protocol": "tcp",
"containerPort": 8082
}
],
"environmentFiles": [
{
"value": "arn:aws:s3:::2fas-production-env/pass.env",
"type": "s3"
}
],
"secrets": [
{
"name": "FIREBASE_SA",
"valueFrom": "arn:aws:secretsmanager:us-east-2:<AWS_ACCOUNT_ID>:secret:prod/pass-8pVN76:pass_firebase_sa::"
}
],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group" : "/ecs/2fas-pass",
"awslogs-region": "us-east-2",
"awslogs-stream-prefix": "ecs"
}
}
}
],
"requiresCompatibilities": [
"FARGATE"
],
"networkMode": "awsvpc",
"family": "2fas-pass",
"cpu": "256",
"memory": "512"
}
35 changes: 35 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,41 @@ services:
- shared-volume:/tmp/2fas
command: chown -R 1000:1000 /tmp/2fas

pass:
build:
context: .
dockerfile: docker/pass/Dockerfile
group_add:
- '1000'
ports:
- "8088:8082"
environment:
# overwrite AWS_ENDPOINT from .env file. One in env is used to running app from local also.
AWS_ENDPOINT: http://localstack-main:4566
AWS_REGION: us-east-1
env_file:
- .env
depends_on:
localstack:
condition: service_healthy

localstack:
container_name: "${LOCALSTACK_DOCKER_NAME:-localstack-main}"
image: localstack/localstack
ports:
- "127.0.0.1:4566:4566"
environment:
- DEBUG=1
healthcheck:
test: >-
curl -s localhost:4566/_localstack/health | grep -q '"kms": "running"'
interval: 5s
timeout: 5s
retries: 5
volumes:
- "./e2e-tests/localstack_init.sh:/etc/localstack/init/ready.d/localstack_init.sh" # ready hook
- "./data/localstack:/var/lib/localstack"
- "/var/run/docker.sock:/var/run/docker.sock"

volumes:
go-modules:
Expand Down
30 changes: 30 additions & 0 deletions docker/pass/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM golang:1.21-alpine as build

ENV GO111MODULE=on \
CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64

WORKDIR /go/src/2fas

COPY go.mod go.sum ./

RUN go mod download -x

COPY . .

RUN mkdir -p bin

RUN go build -trimpath -o bin/pass ./cmd/pass/main.go

FROM alpine:latest

RUN adduser 2fas -D

USER 2fas

WORKDIR /home/2fas/

COPY --from=build /go/src/2fas/bin/* /usr/local/bin/

CMD ["pass"]
18 changes: 18 additions & 0 deletions e2e-tests/localstack_init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh

apt install --assume-yes jq

AWS_REGION=us-east-1
KEY_ALIAS=pass_service_signing_key

response=$(awslocal kms create-key \
--region $AWS_REGION \
--key-usage SIGN_VERIFY \
--customer-master-key-spec ECC_NIST_P256)

key_id=$(echo "${response}" | jq -r '.KeyMetadata.KeyId')

awslocal kms create-alias \
--region $AWS_REGION \
--alias-name "alias/$KEY_ALIAS" \
--target-key-id "${key_id}"
Loading
Loading