package
0.23.2
Repository: https://github.com/mainfluxlabs/mainflux.git
Documentation: pkg.go.dev

# README

Auth - Authentication and Authorization service

Auth service provides authentication features as an API for managing authentication keys as well as administering groups of entities - things and users.

Authentication

User service is using Auth service gRPC API to obtain login token or password reset token. Authentication key consists of the following fields:

  • ID - key ID
  • Type - one of the three types described below
  • IssuerID - an ID of the Mainflux User who issued the key
  • Subject - user email
  • IssuedAt - the timestamp when the key is issued
  • ExpiresAt - the timestamp after which the key is invalid

There are three types of authentication keys:

  • User key - keys issued to the user upon login request
  • API key - keys issued upon the user request
  • Recovery key - password recovery key

Authentication keys are represented and distributed by the corresponding JWT.

User keys are issued when user logs in. Each user request (other than registration and login) contains user key that is used to authenticate the user.

API keys are similar to the User keys. The main difference is that API keys have configurable expiration time. If no time is set, the key will never expire. For that reason, API keys are the only key type that can be revoked. This also means that, despite being used as a JWT, it requires a query to the database to validate the API key. The user with API key can perform all the same actions as the user with login key (can act on behalf of the user for Thing, Channel, or user profile management), except issuing new API keys.

Recovery key is the password recovery key. It's short-lived token used for password recovery process.

For in-depth explanation of the aforementioned scenarios, as well as thorough understanding of Mainflux, please check out the official documentation.

The following actions are supported:

  • create (all key types)
  • verify (all key types)
  • obtain (API keys only)
  • revoke (API keys only)

Groups

User and Things service are using Auth gRPC API to get the list of ids that are part of a group. Groups can be organized as tree structure. Group consists of the following fields:

  • ID - ULID id uniquely representing group
  • Name - name of the group, name of the group is unique at the same level of tree hierarchy for a given tree.
  • ParentID - id of the parent group
  • OwnerID - id of the user that created a group
  • Description - free form text, up to 1024 characters
  • Metadata - Arbitrary, object-encoded group's data
  • Path - tree path consisting of group ids
  • CreatedAt - timestamp at which the group is created
  • UpdatedAt - timestamp at which the group is updated

Configuration

The service is configured using the environment variables presented in the following table. Note that any unset variables will be replaced with their default values.

VariableDescriptionDefault
MF_AUTH_LOG_LEVELService level (debug, info, warn, error)error
MF_AUTH_DB_HOSTDatabase host addresslocalhost
MF_AUTH_DB_PORTDatabase host port5432
MF_AUTH_DB_USERDatabase usermainflux
MF_AUTH_DB_PASSWORDDatabase passwordmainflux
MF_AUTH_DBName of the database used by the serviceauth
MF_AUTH_DB_SSL_MODEDatabase connection SSL mode (disable, require, verify-ca, verify-full)disable
MF_AUTH_DB_SSL_CERTPath to the PEM encoded certificate file
MF_AUTH_DB_SSL_KEYPath to the PEM encoded key file
MF_AUTH_DB_SSL_ROOT_CERTPath to the PEM encoded root certificate file
MF_AUTH_HTTP_PORTAuth service HTTP port8180
MF_AUTH_GRPC_PORTAuth service gRPC port8181
MF_AUTH_SERVER_CERTPath to server certificate in pem format
MF_AUTH_SERVER_KEYPath to server key in pem format
MF_AUTH_SECRETString used for signing tokensauth
MF_AUTH_LOGIN_TOKEN_DURATIONThe login token expiration period10h
MF_JAEGER_URLJaeger server URLlocalhost:6831

Deployment

The service itself is distributed as Docker container. Check the auth service section in docker-compose to see how service is deployed.

To start the service outside of the container, execute the following shell script:

# download the latest version of the service
go get github.com/MainfluxLabs/mainflux

cd $GOPATH/src/github.com/MainfluxLabs/mainflux

# compile the service
make auth

# copy binary to bin
make install

# set the environment variables and run the service
MF_AUTH_LOG_LEVEL=[Service log level] MF_AUTH_DB_HOST=[Database host address] MF_AUTH_DB_PORT=[Database host port] MF_AUTH_DB_USER=[Database user] MF_AUTH_DB_PASS=[Database password] MF_AUTH_DB=[Name of the database used by the service] MF_AUTH_DB_SSL_MODE=[SSL mode to connect to the database with] MF_AUTH_DB_SSL_CERT=[Path to the PEM encoded certificate file] MF_AUTH_DB_SSL_KEY=[Path to the PEM encoded key file] MF_AUTH_DB_SSL_ROOT_CERT=[Path to the PEM encoded root certificate file] MF_AUTH_HTTP_PORT=[Service HTTP port] MF_AUTH_GRPC_PORT=[Service gRPC port] MF_AUTH_SECRET=[String used for signing tokens] MF_AUTH_SERVER_CERT=[Path to server certificate] MF_AUTH_SERVER_KEY=[Path to server key] MF_JAEGER_URL=[Jaeger server URL] MF_AUTH_LOGIN_TOKEN_DURATION=[The login token expiration period] $GOBIN/mainfluxlabs-auth

If MF_EMAIL_TEMPLATE doesn't point to any file service will function but password reset functionality will not work.

Usage

For more information about service capabilities and its usage, please check out the API documentation.

# Packages

Package api contains implementation of Auth service HTTP API.
No description provided by the author
No description provided by the author
Package postgres contains Key repository implementations using PostgreSQL as the underlying database.
Package tracing contains middlewares that will add spans to existing traces.

# Functions

New instantiates the auth service implementation.

# Constants

No description provided by the author
APIKey enables the one to act on behalf of the user.
No description provided by the author
LoginKey is temporary User key received on successful login.
No description provided by the author
No description provided by the author
RecoveryKey represents a key for resseting password.
RoleAdmin is the admin role.
RoleRootAdmin is the super admin role.
No description provided by the author
No description provided by the author

# Variables

ErrAPIKeyExpired indicates that the Key is expired and that the key type is API key.
ErrAssignGroup indicates failure to assign group to org.
ErrAssignMember indicates failure to assign member to org.
ErrFailedToRetrieveMembersByOrg failed to retrieve members by org.
ErrFailedToRetrieveOrgsByMember failed to retrieve orgs by member.
ErrInvalidKeyIssuedAt indicates that the Key is being used before it's issued.
ErrKeyExpired indicates that the Key is expired.
ErrOrgGroupAlreadyAssigned indicates that group is already assigned.
ErrOrgMemberAlreadyAssigned indicates that members is already assigned.
ErrOrgNotEmpty indicates org is not empty, can't be deleted.
ErrUnassignGroup indicates failure to unassign group from org.
ErrUnassignMember indicates failure to unassign member from an org.

# Structs

AuthzReq represents an argument struct for making an authz related function calls.
No description provided by the author
Identity contains ID and Email.
Key represents API key.
Org represents the org information.
No description provided by the author
No description provided by the author
OrgMembersPage contains page related metadata as well as list of members that belong to this page.
OrgsPage contains page related metadata as well as list of orgs that belong to this page.
PageMetadata contains page metadata that helps navigation.
No description provided by the author

# Interfaces

Authn specifies an API that must be fullfiled by the domain service implementation, and all of its decorators (e.g.
Authz represents a authorization service.
KeyRepository specifies Key persistence API.
OrgRepository specifies an org persistence API.
Orgs specifies an API that must be fullfiled by the domain service implementation, and all of its decorators (e.g.
No description provided by the author
No description provided by the author
Service specifies an API that must be fulfilled by the domain service implementation, and all of its decorators (e.g.
Tokenizer specifies API for encoding and decoding between string and Key.

# Type aliases

OrgMetadata defines the Metadata type.