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

Feature/rest api #25

Merged
merged 70 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
6278664
remove echo
MGTheTrain Dec 19, 2024
78dc5ec
consider member attributes private
MGTheTrain Dec 20, 2024
43db667
setup dtos, handlers and routes; remove obsolete files for v1 package
MGTheTrain Dec 20, 2024
ec89a24
consider error in tuple for New...(...) functions for consistency
MGTheTrain Dec 20, 2024
2ccd12d
modify entrypoint of REST service app
MGTheTrain Dec 20, 2024
1712c90
rename blob and key handler methods
MGTheTrain Dec 20, 2024
f9d38fe
internally generate key pair id
MGTheTrain Dec 20, 2024
50dcb2f
consider member attributes private
MGTheTrain Dec 20, 2024
74a10b8
consider download endpoints
MGTheTrain Dec 20, 2024
aba5f9b
update method and function descriptions
MGTheTrain Dec 20, 2024
9819e58
align api-v1 document
MGTheTrain Dec 20, 2024
416bfb8
ignore tmp/temp files
MGTheTrain Dec 20, 2024
6b0074c
modify queries for list responses
MGTheTrain Dec 20, 2024
00f0165
add default values in yml config files
MGTheTrain Dec 21, 2024
f8c18ab
add viper package and Config struct with function loading the config …
MGTheTrain Dec 21, 2024
e1099bc
prioritize environment variables and fall back to config file
MGTheTrain Dec 21, 2024
c511de6
add/modify settings utilized in entrypoint
MGTheTrain Dec 21, 2024
e12fd9a
ensure map_structure values align with yml key names
MGTheTrain Dec 21, 2024
9b702a8
consider port in config
MGTheTrain Dec 21, 2024
aa84e9a
consider single configuration file for ease of maintainance
MGTheTrain Dec 21, 2024
7930d59
only create database if it does not exist
MGTheTrain Dec 21, 2024
20d1efa
adjust default values in yml file
MGTheTrain Dec 21, 2024
9eaa90f
dockerize service
MGTheTrain Dec 21, 2024
5798750
remove obsolete Make target
MGTheTrain Dec 21, 2024
7792d3a
print info in case config file could not be loaded
MGTheTrain Dec 21, 2024
6ac1e91
remove \r characters in env file
MGTheTrain Dec 21, 2024
05f0d64
fix InitializeConfig(...) logic
MGTheTrain Dec 21, 2024
19b23b4
add launch json
MGTheTrain Dec 21, 2024
c16c6c4
rename config file
MGTheTrain Dec 21, 2024
fd7f370
adjust env vars to align with mapstructure values
MGTheTrain Dec 21, 2024
e71ee3c
workaround by constructing the config object when environment variabl…
MGTheTrain Dec 21, 2024
0c96e5e
adjust path and call correct method
MGTheTrain Dec 21, 2024
0a045ea
remove obsolete gitkeep
MGTheTrain Dec 21, 2024
ebefb1c
ensure correct dsn value is assigned for database connection
MGTheTrain Dec 21, 2024
7cb3263
utilize double quotation mark for values
MGTheTrain Dec 21, 2024
b2021cf
fix Dockerfile
MGTheTrain Dec 21, 2024
a40816e
utilize relative path
MGTheTrain Dec 21, 2024
3c3114f
remove flag targeting architecture for the Go program
MGTheTrain Dec 21, 2024
3a5071b
consider restart: on-failure key-value pair
MGTheTrain Dec 21, 2024
884ce99
remove flags when building Go app
MGTheTrain Dec 21, 2024
9039e01
add make target to generate swagger docs
MGTheTrain Dec 21, 2024
abe9593
add swagger annotations
MGTheTrain Dec 21, 2024
d9a8b57
go mod tidy
MGTheTrain Dec 21, 2024
9b6cfbb
generate swagger docs
MGTheTrain Dec 21, 2024
c81b11c
modify default version value
MGTheTrain Dec 21, 2024
0b50f97
add swaggo packages
MGTheTrain Dec 21, 2024
69045e4
add endpoint fetching swagger files
MGTheTrain Dec 21, 2024
12959f6
enable endpoint for serving swagger files
MGTheTrain Dec 21, 2024
4d4ebb3
add dockerignore
MGTheTrain Dec 21, 2024
816b067
modify README for crypto-vault-service app
MGTheTrain Dec 21, 2024
deaeacc
fix Router annotations and update swagger docs
MGTheTrain Dec 21, 2024
8b3b855
consider CloudProvider attribute when creating connector settings obj…
MGTheTrain Dec 22, 2024
22905d1
fix values in annotations for query structs
MGTheTrain Dec 22, 2024
ab40c94
add BasePath const global variable in version file
MGTheTrain Dec 22, 2024
58f8281
set docs components attributes
MGTheTrain Dec 22, 2024
2f2a363
generate swagger docs
MGTheTrain Dec 22, 2024
1384d4e
rename variables and explicitly initialize it as an empty slice
MGTheTrain Dec 22, 2024
de6c8e7
ensure foreign key ids can be set to nil
MGTheTrain Dec 22, 2024
e673a6d
prevent dereferencing potential nil pointer
MGTheTrain Dec 22, 2024
e8fffc6
generate swagger docs
MGTheTrain Dec 22, 2024
f4a1da9
update error response message
MGTheTrain Dec 22, 2024
640966a
sign first before encrypting data
MGTheTrain Dec 22, 2024
b90841f
Ensure if the plaintext is too large to split it into smaller chunks …
MGTheTrain Dec 22, 2024
76ae949
handles multiple chunks of encrypted data in RSA decryption
MGTheTrain Dec 22, 2024
3c4326d
refine test case
MGTheTrain Dec 22, 2024
d01750c
refine and check boxes in feature section
MGTheTrain Dec 22, 2024
cff652b
document changes
MGTheTrain Dec 22, 2024
a8bf527
remove obsolete comment
MGTheTrain Dec 22, 2024
7f61ce9
add temporary .gitkeep for smoke tests dir
MGTheTrain Dec 22, 2024
adff47d
improve response messages and fix linter findings
MGTheTrain Dec 22, 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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ go.work
go.work.sum

# env file
.env
.env

# tmp files
*.tmp
*.temp
35 changes: 35 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}",
"env": {
"PORT": "8080",
"DATABASE_TYPE": "postgres",
"DATABASE_DSN": "user=postgres password=postgres host=localhost port=5432 sslmode=disable",
"DATABASE_NAME": "meta",
"BLOB_CONNECTOR_CLOUD_PROVIDER": "azure",
"BLOB_CONNECTOR_CONNECTION_STRING": "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;",
"BLOB_CONNECTOR_CONTAINER_NAME": "blobs",
"KEY_CONNECTOR_CLOUD_PROVIDER": "azure",
"KEY_CONNECTOR_CONNECTION_STRING": "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;",
"KEY_CONNECTOR_CONTAINER_NAME": "keys",
"LOGGER_LOG_LEVEL": "info",
"LOGGER_LOG_TYPE": "console",
"LOGGER_FILE_PATH": "",
"PKCS11_MODULE_PATH": "/usr/lib/softhsm/libsofthsm2.so",
"PKCS11_SO_PIN": "123456",
"PKCS11_USER_PIN": "234567",
"PKCS11_SLOT_ID": "0x0"
}
}
]
}
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **Logging**: Integrated console and file logging (e.g. using structured logging with `logrus`)
- **Manage cryptographic material**: Enabled management of private/public key pairs and symmetric keys and implemented key lifecycle management including primarily key generation and key export
- **Secure file storage integration**: Provided mechanisms to securely store encrypted files in Azure Blob Storage
- **RESTful API**: Provided HTTP endpoints to manage cryptographic material and secure data (files, metadata) at rest.
- **Documentation**: Provided clear API documentation (e.g. Swagger/OpenAPI) for ease of integration by other developers.
- **Versioning**: Implemented proper API versioning to maintain backward compatibility as the API evolves.

## [0.1.0] - TBD-TBD-TBD

Expand Down
29 changes: 11 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,37 @@ SCRIPT_DIR = "scripts"

.PHONY: format-and-lint run-unit-tests run-integration-tests \
spin-up-integration-test-docker-containers \
shut-down-integration-test-docker-containers \
spin-up-docker-containers shut-down-docker-containers help
spin-up-docker-containers shut-down-docker-containers \
generate-swagger-docs help

# Help target to list all available targets
help:
@echo "Available Makefile targets:"
@echo " format-and-lint - Run the format and linting script"
@echo " run-unit-tests - Run the unit tests"
@echo " run-integration-tests - Run the integration tests"
@echo " format-and-lint - Run the format and linting script"
@echo " run-unit-tests - Run the unit tests"
@echo " run-integration-tests - Run the integration tests"
@echo " spin-up-integration-test-docker-containers - Spin up Docker containers for integration tests (Postgres, Azure Blob Storage)"
@echo " shut-down-integration-test-docker-containers - Shut down Docker containers for integration tests"
@echo " spin-up-docker-containers - Spin up Docker containers with internal containerized applications"
@echo " shut-down-docker-containers - Shut down the application Docker containers"
@echo " spin-up-docker-containers - Spin up Docker containers with internal containerized applications"
@echo " shut-down-docker-containers - Shut down the application Docker containers"
@echo " generate-swagger-docs - Convert Go annotations to Swagger Documentation 2.0"

# Run the format and lint script
format-and-lint:
@cd $(SCRIPT_DIR) && ./format-and-lint.sh

# Run unit tests
run-unit-tests:
@cd $(SCRIPT_DIR) && ./run-test.sh -u

# Run integration tests
run-integration-tests:
@cd $(SCRIPT_DIR) && ./run-test.sh -i

# Spin up Docker containers for integration tests
spin-up-integration-test-docker-containers:
docker-compose up -d postgres azure-blob-storage

# Shut down Docker containers for integration tests
shut-down-integration-test-docker-containers:
docker-compose down postgres azure-blob-storage -v

# Spin up Docker containers with internal containerized applications
spin-up-docker-containers:
docker-compose up -d --build

# Shut down Docker containers with internal containerized applications
shut-down-docker-containers:
docker-compose down -v

generate-swagger-docs:
@cd $(SCRIPT_DIR) && ./generate-docs.sh
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ Interfaces (CLIs, gRPC APIs, RESTful Web APIs) for managing cryptographic keys a

### Functional

- [ ] **Provide RESTful API**: Expose HTTP endpoints to manage cryptographic material and secure data (files, metadata) at rest.
- [ ] **Provide gRPC API**: Expose gRPC endpoints to manage cryptographic material and secure data (files, metadata) at rest.
- [x] **RESTful API**: Provide HTTP endpoints to manage cryptographic material and secure data (files, metadata) at rest.
- [ ] **gRPC API**: Provide gRPC endpoints to manage cryptographic material and secure data (files, metadata) at rest.
- [x] **Asymmetric encryption and decryption**: Support RSA encryption algorithm for data protection.
- [x] **Symmetric encryption**: Support for symmetric key encryption (e.g. AES) for data protection.
- [x] **Signature creation and verification:** Support for hashing algorithms (e.g. SHA-256, SHA-512) to create digital signatures and the ability to verify these signatures using asymmetric keys (RSA, ECDSA).
- [x] **PKCS#11 integration**: Enable key management and cryptographic operations (such as RSA-PKCS encryption/decryption and RSA-PSS or ECDSA signing/verification) through PKCS#11 interfaces supporting both FIPS-compliant hardware and software environments.
- [ ] **Manage cryptographic material and Key management lifecycle**: Enable management of private/public key pairs and symmetric keys and implement key lifecycle management
- [x] Generation
- [ ] ~~Import~~ (keys can only be generated by the system)
- [x] Export (only public keys for verifying signatures shall be exported trough API endpoints)
- [x] Export
- [ ] Rotation
- [ ] Revocation
- [ ] Expiration
Expand All @@ -48,11 +48,10 @@ Interfaces (CLIs, gRPC APIs, RESTful Web APIs) for managing cryptographic keys a
- [ ] **Performance optimization**: Ensure cryptographic operations are optimized for performance, especially for large files and high throughput environments.
- [x] **Logging**: Integrate logging (e.g. using structured logging with `logrus`)
- [ ] **Monitoring**: Integrate monitoring (e.g. Prometheus, Grafana) to track API usage, performance and errors.
- [ ] **Error handling and resiliency**: Implement comprehensive error handling and retries for operations that may fail, with clear error messages and status codes for the API.
- [ ] **Security**: Ensure that all cryptographic material and metadata is securely encrypted before storing it using a master key
- [ ] **Access control**: Secure APIs using authorization mechanisms including OAuth 2.0 and JWTs. Implement relationship-based access control (ReBAC) for APIs, ensuring that users can only perform operations on cryptographic material based on their defined relationships and permissions within the system.
- [ ] **Documentation**: Provide clear API documentation (e.g. Swagger/OpenAPI) for ease of integration by other developers.
- [ ] **Versioning**: Implement proper API versioning to maintain backward compatibility as the API evolves.
- [x] **Documentation**: Provide clear API documentation (e.g. Swagger/OpenAPI) for ease of integration by other developers.
- [x] **Versioning**: Implement proper API versioning to maintain backward compatibility as the API evolves.
- [ ] **Audit logging**: Maintain logs of all cryptographic operations and key management activities for compliance and auditing purposes.


Expand Down Expand Up @@ -96,7 +95,7 @@ To run `integration tests` on Unix systems execute
```sh
make spin-up-integration-test-docker-containers
make run-integration-tests
make shut-down-integration-test-docker-containers # Optionally clear docker resources
make shut-down-docker-containers
```

### Applications
Expand Down
29 changes: 29 additions & 0 deletions cmd/crypto-vault-service/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work
go.work.sum

# env file
.env

# tmp files
*.tmp
*.temp
22 changes: 22 additions & 0 deletions cmd/crypto-vault-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Build stage
FROM golang:1.21-alpine AS build

WORKDIR /app

RUN apk update
COPY go.mod go.sum ./
RUN go mod tidy
COPY . .
RUN go build -o crypto_vault_service ./cmd/crypto-vault-service/crypto_vault_service.go

# Serve stage
FROM alpine:latest

WORKDIR /root/

RUN apk update && apk add --no-cache libc6-compat
COPY --from=build /app/crypto_vault_service .

EXPOSE 8080

ENTRYPOINT ["./crypto_vault_service"]
4 changes: 2 additions & 2 deletions cmd/crypto-vault-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

## Summary

TBD
REST service capable of managing cryptographic keys and securing data at rest (metadata, BLOB)

## Getting Started

TBD
Set up your IDE with the necessary Go tooling (such as the `delve` debugger) or use the provided [devcontainer.json file](../../.devcontainer/devcontainer.json). You can start the service by either running `go run crypto_vault_service.go` from this directory or by using the `spin-up-docker-containers Make target` from the [Makefile](../../Makefile). To explore the Swagger Web UI you need to either visit `http://localhost:8080/api/v1/cvs/swagger/index.html` or `http://localhost:5000/api/v1/cvs/swagger/index.html`.
Loading
Loading