Categorygithub.com/Falokut/accounts_service
repository
0.0.0-20240320151102-129bed4f3eab
Repository: https://github.com/falokut/accounts_service.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author

# README

Accounts service

Go Report Card go.dev reference GitHub go.mod Go version Go License

Content


About service

The Account Service is a robust and secure service that provides essential functionalities for user accounts management. It offers a seamless user experience with features such as registration, password reset, account confirmation, login, and authentication.

Features

  1. Registration: Users can create new accounts by providing their basic information, including email and password. The registration process ensures that only valid and unique email addresses are accepted.

  2. Password Reset: In case users forget their passwords, the service allows them to initiate a password reset procedure. A secure link is sent to the user's registered email address, enabling them to set a new password and regain access to their account.

  3. Account Confirmation: To enhance security and prevent abuse, newly registered users must confirm their email addresses. A confirmation link is sent to the provided email, and upon verification, the account is activated within the system.

  4. Login: Once registered and confirmed, users can securely log in to their accounts using their email and password. The service utilizes robust authentication protocols to protect account information and ensure secure access.

  5. Authentication: To enhance security and prevent unauthorized access, the service employs authentication methods such as session-based identification and client identification based on their machine ID. If the machine ID provided in the request does not match the one stored in the session cache, access will be denied. These security measures ensure the safeguarding of user accounts and help in protecting against unauthorized access.

The Account Service provides a reliable, efficient, and user-friendly solution for managing user accounts in web applications. With its comprehensive set of features, it ensures the security and integrity of user data, delivering a seamless login and account management experience.

Accounts and authentication

The accounts service features a login system where users can securely log in via sessions. This system ensures that only approved users can perform actions with their accounts.

To create an account, users can register by providing their email and password. Once registered and confirmed emails, users can log in to their accounts using their credentials. The system will generate a session token for the user, which they will use for authentication in future requests.

Users remaster logged in until they manually log out or their session expires. This eliminates the need for users to repeatedly authenticate themselves for each request, providing a seamless experience.

Users can safely access the services using their account information. Additionally, it's worth noting that passwords are encrypted and not stored in plain text. Instead, they are encrypted using encryption algorithm bcrypt. This provides an added layer of security, as even in the event of a data breach, it would be extremely difficult for malicious actors to recover and exploit these passwords.

When registering a new account, the entered passwords are securely encrypted before being stored in the database. This way, user passwords are protected from unauthorized access.

Registration

During the registration process, an email confirmation link is sent to the user's provided email address (need another request). The user must click on this link to verify their account and activate it. Once the email is confirmed, the account information is securely transferred from the Redis cache to the master database.

Implementing this email verification step helps ensure that only legitimate users with valid email addresses can create accounts on the cinema ticket. It helps prevent potential abuse or unauthorized access by requiring users to verify their identities before gaining full access to the system.


Events

The service generate 2 types of events: requests for the delivery of tokens to the user and events that occur with the accounts(its creation, deletion, change of email). events package


Configuration

  1. Create .env in root dir
    Example env for redis:
REDIS_PASSWORD=redispass
REDIS_AOF_ENABLED=no
  1. Configure accounts_db
  2. Create a configuration file or change the config.yml file in docker\containers-configs. If you are creating a new configuration file, specify the path to it in docker-compose volume section (your-path/config.yml:configs/)
  3. Configure kafka broker example compose file

Configuration params info

if supported values is empty, then any type values are supported

yml nameyml sectionenv nameparam typedescriptionsupported values
log_levelLOG_LEVELstringlogging levelpanic, fatal, error, warning, warn, info, debug, trace
profiles_service_addrPROFILES_SERVICE_ADDRstringip address(or host) with port of profiles serviceall valid addresses formatted like host:port or ip-address:port
healthcheck_portHEALTHCHECK_PORTstringport for healthcheckany valid port that is not occupied by other services. The string should not contain delimiters, only the port number
hostlistenHOSTstringip address or host to listen
portlistenPORTstringport to listenThe string should not contain delimiters, only the port number
server_modelistenSERVER_MODEstringServer listen mode, Rest API, gRPC or bothGRPC, REST, BOTH
allowed_headerslisten[]string, array of stringslist of all allowed custom headers. Need for REST API gateway, list of metadata headers, hat are passed through the gateway into the serviceany strings list
allowed_outgoing_headerlistenmap[string]stringmap of headers, thath passess throught gateway from service (outgoing headers), which key is pretty header name, value is header name inside serviceany map with string key and value string
service_nameprometheusPROMETHEUS_SERVICE_NAMEstringservice name, thats will show in prometheus
server_configprometheusnested yml configuration metrics server config
nonactivated_account_ttltime.Duration with positive durationthe time that registered(non activated) account will be stored in the cachesupported values
sessions_ttltime.Duration with positive durationthe time that session will be stored in the cachesupported values
db_confignested yml configuration database configconfiguration for database connection
jaegernested yml configuration jaeger configconfiguration for jaeger connection
networkregistration_repositoryREGISTRATION_REPOSITORY_NETWORKstringtcp or udp
addrregistration_repositoryREGISTRATION_REPOSITORY_ADDRESSstringip address(or host) with port of redisall valid addresses formatted like host:port or ip-address:port
passwordregistration_repositoryREGISTRATION_REPOSITORY_PASSWORDstringpassword for connection to the redis
dbregistration_repositoryREGISTRATION_REPOSITORY_DATABASEintthe number of the database in the redis
networksessions_repositorySESSIONS_REPOSITORY_NETWORKstringtcp or udp
addrsessions_repositorySESSIONS_REPOSITORY_ADDRESSstringip address(or host) with port of redisall valid addresses formatted like host:port or ip-address:port
passwordsessions_repositorySESSIONS_REPOSITORY_PASSWORDstringpassword for connection to the redis
dbsessions_repositorySESSIONS_REPOSITORY_DATABASEintthe number of the database in the redis
num_retries_for_terminate_sessionsintnumber of retries for session termination, when deleting account
retry_sleep_time_for_terminate_sessionstime.Duration with positive durationthe time delay between session deletion retriessupported values
bcrypt_costcryptoBCRYPT_COSTintthe bcrypt hashing complexity4-31
ttlchange_password_tokentime.Duration with positive durationthe amount of time this token will be valid forsupported values
secretchange_password_tokenCHANGE_PASSWORD_TOKEN_SECRETstringthe secret to generating a jwt token
ttlverify_account_tokentime.Duration with positive durationthe amount of time this token will be valid forsupported values
secretverify_account_tokenVERIFY_ACCOUNT_TOKEN_SECRETstringthe secret to generating a jwt token
brokersaccount_events[]string, array of stringslist of the addresses of kafka brokersany list of addresses like host:port or ip-address:port
brokerstokens_delivery[]string, array of stringslist of the addresses of kafka brokersany list of addresses like host:port or ip-address:port

Database config

yml nameenv nameparam typedescriptionsupported values
hostDB_HOSTstringhost or ip address of database
portDB_PORTstringport of databaseany valid port that is not occupied by other services. The string should not contain delimiters, only the port number
usernameDB_USERNAMEstringusername(role) in database
passwordDB_PASSWORDstringpassword for role in database
db_nameDB_NAMEstringdatabase name (database instance)
ssl_modeDB_SSL_MODEstringenable or disable ssl mode for database connectiondisabled or enabled

Kafka config

yml nameenv nameparam typedescriptionsupported values
brokers[]string, array of stringslist of the addresses of kafka brokersany list of addresses like host:port or ip-address:port
topicstringtopic nameany topic name

Jaeger config

yml nameenv nameparam typedescriptionsupported values
addressJAEGER_ADDRESSstringhip address(or host) with port of jaeger serviceall valid addresses formatted like host:port or ip-address:port
service_nameJAEGER_SERVICE_NAMEstringservice name, thats will show in jaeger in traces
log_spansJAEGER_LOG_SPANSboolwhether to enable log scans in jaeger for this service or not

Prometheus config

yml nameenv nameparam typedescriptionsupported values
hostMETRIC_HOSTstringip address or host to listen for prometheus service
portMETRIC_PORTstringport to listen for of prometheus serviceany valid port that is not occupied by other services. The string should not contain delimiters, only the port number

time.Duration yaml supported values

A Duration value can be expressed in various formats, such as in seconds, minutes, hours, or even in nanoseconds. Here are some examples of valid Duration values:

  • 5s represents a duration of 5 seconds.
  • 1m30s represents a duration of 1 minute and 30 seconds.
  • 2h represents a duration of 2 hours.
  • 500ms represents a duration of 500 milliseconds.
  • 100µs represents a duration of 100 microseconds.
  • 10ns represents a duration of 10 nanoseconds.

Metrics

The service uses Prometheus and Jaeger and supports distributed tracing

Docs

Swagger docs

Author

  • @Falokut - Primary author of the project

License

This project is licensed under the terms of the MIT License.