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

NOISSUE - Separate Keto hosts for read and write #1563

Merged
merged 5 commits into from
Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
4 changes: 4 additions & 0 deletions auth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ default values.
| MF_AUTH_SECRET | String used for signing tokens | auth |
| MF_AUTH_LOGIN_TOKEN_DURATION | The login token expiration period | 10h |
| MF_JAEGER_URL | Jaeger server URL | localhost:6831 |
| MF_KETO_READ_REMOTE_HOST | Keto Read Host | mainflux-keto |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it OK that they have identical host/container names? These are two different containers if I understand well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same container.
In docker deployment keto expose read and write on the same host with different ports.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR doesn't change anything in keto deployment. It just enables Auth service to have separate URLs for read and write connection to Keto. That wasn't possible because Auth used the same environment variable for both read and write connection

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it be 2 different hosts? If not, then use one host with 2 ports, i.e. add just one variable: MF_KETO_REMOTE_HOST and two env vars for ports: MF_KETO_READ_REMOTE_PORT and MF_KETO_WRITE_REMOTE_PORT (additionally - do we need word "REMOTE" in these and do we use it in other var names?).

Copy link
Contributor Author

@blokovi blokovi Feb 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@drasko What you suggest is that nothing to change, that's how it is now.

But we need Auth service to be capable to connect to two different keto hosts, not just the same host and different ports.
That is because in k8s setup keto read and write endpoints are on different hosts.
So, we can have like in this PR four envars (for read host, read port, write host, write port) or maybe two envars (each in host:port format). In any way we need possibility to configure differently both host and port part of connection urls

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, thanks

| MF_KETO_WRITE_REMOTE_HOST | Keto Write Host | mainflux-keto |
| MF_KETO_READ_REMOTE_PORT | Keto Read Port | 4466 |
| MF_KETO_WRITE_REMOTE_PORT | Keto Write Port | 4467 |

## Deployment

Expand Down
30 changes: 17 additions & 13 deletions cmd/auth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ const (
defServerCert = ""
defServerKey = ""
defJaegerURL = ""
defKetoHost = "mainflux-keto"
defKetoWritePort = "4467"
defKetoReadHost = "mainflux-keto"
defKetoWriteHost = "mainflux-keto"
defKetoReadPort = "4466"
defKetoWritePort = "4467"
defLoginDuration = "10h"

envLogLevel = "MF_AUTH_LOG_LEVEL"
Expand All @@ -71,9 +72,10 @@ const (
envServerCert = "MF_AUTH_SERVER_CERT"
envServerKey = "MF_AUTH_SERVER_KEY"
envJaegerURL = "MF_JAEGER_URL"
envKetoHost = "MF_KETO_HOST"
envKetoWritePort = "MF_KETO_WRITE_REMOTE_PORT"
envKetoReadHost = "MF_KETO_READ_REMOTE_HOST"
envKetoWriteHost = "MF_KETO_WRITE_REMOTE_HOST"
envKetoReadPort = "MF_KETO_READ_REMOTE_PORT"
envKetoWritePort = "MF_KETO_WRITE_REMOTE_PORT"
envLoginDuration = "MF_AUTH_LOGIN_TOKEN_DURATION"
)

Expand All @@ -87,7 +89,8 @@ type config struct {
serverKey string
jaegerURL string
resetURL string
ketoHost string
ketoReadHost string
ketoWriteHost string
ketoWritePort string
ketoReadPort string
loginDuration time.Duration
Expand Down Expand Up @@ -115,7 +118,7 @@ func main() {
dbTracer, dbCloser := initJaeger("auth_db", cfg.jaegerURL, logger)
defer dbCloser.Close()

readerConn, writerConn := initKeto(cfg.ketoHost, cfg.ketoReadPort, cfg.ketoWritePort, logger)
readerConn, writerConn := initKeto(cfg.ketoReadHost, cfg.ketoReadPort, cfg.ketoWriteHost, cfg.ketoWritePort, logger)

svc := newService(db, dbTracer, cfg.secret, logger, readerConn, writerConn, cfg.loginDuration)
errs := make(chan error, 2)
Expand Down Expand Up @@ -160,7 +163,8 @@ func loadConfig() config {
serverCert: mainflux.Env(envServerCert, defServerCert),
serverKey: mainflux.Env(envServerKey, defServerKey),
jaegerURL: mainflux.Env(envJaegerURL, defJaegerURL),
ketoHost: mainflux.Env(envKetoHost, defKetoHost),
ketoReadHost: mainflux.Env(envKetoReadHost, defKetoReadHost),
ketoWriteHost: mainflux.Env(envKetoWriteHost, defKetoWriteHost),
ketoReadPort: mainflux.Env(envKetoReadPort, defKetoReadPort),
ketoWritePort: mainflux.Env(envKetoWritePort, defKetoWritePort),
loginDuration: loginDuration,
Expand Down Expand Up @@ -192,20 +196,20 @@ func initJaeger(svcName, url string, logger logger.Logger) (opentracing.Tracer,
return tracer, closer
}

func initKeto(hostAddress, readPort, writePort string, logger logger.Logger) (readerConnection, writerConnection *grpc.ClientConn) {
checkConn, err := grpc.Dial(fmt.Sprintf("%s:%s", hostAddress, readPort), grpc.WithInsecure())
func initKeto(hostReadAddress, readPort, hostWriteAddress, writePort string, logger logger.Logger) (readerConnection, writerConnection *grpc.ClientConn) {
readConn, err := grpc.Dial(fmt.Sprintf("%s:%s", hostReadAddress, readPort), grpc.WithInsecure())
if err != nil {
logger.Error(fmt.Sprintf("Failed to dial %s:%s for Keto Read Service: %s", hostAddress, readPort, err))
logger.Error(fmt.Sprintf("Failed to dial %s:%s for Keto Read Service: %s", hostReadAddress, readPort, err))
os.Exit(1)
}

writeConn, err := grpc.Dial(fmt.Sprintf("%s:%s", hostAddress, writePort), grpc.WithInsecure())
writeConn, err := grpc.Dial(fmt.Sprintf("%s:%s", hostWriteAddress, writePort), grpc.WithInsecure())
if err != nil {
logger.Error(fmt.Sprintf("Failed to dial %s:%s for Keto Write Service: %s", hostAddress, writePort, err))
logger.Error(fmt.Sprintf("Failed to dial %s:%s for Keto Write Service: %s", hostWriteAddress, writePort, err))
os.Exit(1)
}

return checkConn, writeConn
return readConn, writeConn
}

func connectToDB(dbConfig postgres.Config, logger logger.Logger) *sqlx.DB {
Expand Down
5 changes: 3 additions & 2 deletions docker/.env
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ MF_AUTH_SECRET=secret
MF_AUTH_LOGIN_TOKEN_DURATION="10h"

### Keto
MF_KETO_HOST=mainflux-keto
MF_KETO_WRITE_REMOTE_PORT=4467
MF_KETO_READ_REMOTE_HOST=mainflux-keto
MF_KETO_READ_REMOTE_PORT=4466
MF_KETO_WRITE_REMOTE_HOST=mainflux-keto
MF_KETO_WRITE_REMOTE_PORT=4467
MF_KETO_DB_PORT=5432
MF_KETO_DB_USER=mainflux
MF_KETO_DB_PASS=mainflux
Expand Down
10 changes: 5 additions & 5 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ services:
image: oryd/keto:v0.6.0-alpha.3
container_name: mainflux-keto
ports:
- ${MF_KETO_READ_REMOTE_PORT}:4466
- ${MF_KETO_WRITE_REMOTE_PORT}:4467
- ${MF_KETO_READ_REMOTE_PORT}:${MF_KETO_READ_REMOTE_PORT}
- ${MF_KETO_WRITE_REMOTE_PORT}:${MF_KETO_WRITE_REMOTE_PORT}
environment:
- DSN=postgresql://${MF_KETO_DB_USER}:${MF_KETO_DB_PASS}@keto-db:${MF_KETO_DB_PORT}/${MF_KETO_DB}?sslmode=disable
command: serve -c /home/ory/keto.yml
Expand Down Expand Up @@ -140,10 +140,10 @@ services:
MF_AUTH_SECRET: ${MF_AUTH_SECRET}
MF_AUTH_LOGIN_TOKEN_DURATION: ${MF_AUTH_LOGIN_TOKEN_DURATION}
MF_JAEGER_URL: ${MF_JAEGER_URL}
MF_KETO_HOST: ${MF_KETO_HOST}
MF_KETO_WRITE_REMOTE_PORT: ${MF_KETO_WRITE_REMOTE_PORT}
MF_KETO_READ_REMOTE_HOST: ${MF_KETO_READ_REMOTE_HOST}
MF_KETO_READ_REMOTE_PORT: ${MF_KETO_READ_REMOTE_PORT}

MF_KETO_WRITE_REMOTE_HOST: ${MF_KETO_WRITE_REMOTE_HOST}
MF_KETO_WRITE_REMOTE_PORT: ${MF_KETO_WRITE_REMOTE_PORT}
ports:
- ${MF_AUTH_HTTP_PORT}:${MF_AUTH_HTTP_PORT}
- ${MF_AUTH_GRPC_PORT}:${MF_AUTH_GRPC_PORT}
Expand Down