byGink▻ Tue, 30 Apr 2024
Commonly, basic needs for a log system include:
The first 2 points can be solved by using AWS OpenSearch. As it's a managed service by AWS, similar to ElasticSearch but easier to operate and scale up. With OpenSearch, we can combine with log shippers like Filebeat, Fluent-bit, LogStash to aggregate log data from any sources, including server like EC2, GCE, Azure VM... or even container orchestration like GKE, EKS...
The last point, to be able to assign different permissions. Actually OpenSearch has it own internal user system, but the operator must create user account manually and that's not cool at all. Fortunately, we can combine OpenSearch with AWS Cognito for multiple authentication options like Google, Facebook, OpenID, etc.
So let's see how to do it?
Go to IAM > Roles to create 2 new roles with trust policy and permission as following. We will need these roles to identify our users in OpenSearch.
log-center-master-user-role
log-center-limited-user-role
identity-arn-id
will be updated later when we create the identity pool in Cognito){
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "cognito-identity.amazonaws.com"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"cognito-identity.amazonaws.com:aud": "identity-arn-id"
},
"ForAnyValue:StringLike": {
"cognito-identity.amazonaws.com:amr": "authenticated"
}
}
}
]
}
Permissions:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "es:ESHttpGet",
"Resource": "*"
}
]
}
This is the pool of users can access to OpenSeaarch later. We'll create some groups of users for it.
Amazon Cognito > User pools > Create user pool
us-east-1
region first.OpenSearch will use this pool to identify which user is authenticated. At first, we will create a pool for Guest access, after connect this pool to OpenSearch, it will be disabled automatically and change to Authenticated access.
Then we will specify the user pool created above as the source of users (provider) for this identity pool.
Amazon Cognito > Identity pools > Create identity pool
log-center-guest-user-role
After finishing these steps, we should have 3 roles in IAM, 1 user pool and 1 identity pool in Cognito. Great, let's get to the next step to create OpenSearch domain.
This should be the storage for our log system. It should be scalable because log data is commonly huge. For now AWS provide 2 options: cluster and serverless. We will use cluster because the serverless option is quite limited in feature. At this moment, Cognito can't work with serverless OpenSearch, though it might be changed later.
Amazon OpenSearch Service > Domains > Create domain
us-east-1
.arn:aws:iam::xxx:role/log-center-master-user-role
.CognitoAccessForAmazonOpenSearch
as AWS Console recommends.Things look good now, let's create it.
The process to create OpenSearch domain will take a while. It will also create a new Client in user pool and disable Guest access in identity pool inside Cognito. Wait for it to complete first then we will continue with Cognito.
Remember about the identity-arn-id
we've used in trust policy at the first step? Now we have the identity pool in Cognito already, let's update it back to those roles trust policy.
log-center-master-user-role
, log-center-limited-user-role
, open Trust relationships, click on Edit trust policy.identity-arn-id
with the copied ID.preferred_role
will forward it to OpenSearch.master-users
and connect it with log-center-master-user-role
.log-center-limited-user-role
(optional). It's not required because we will leave this role for users who can login via Google Authentication later.If you can login via that user, congratulation! We're done here.
Let's check my next article on how to configure login OpenSearch with Google Authentication.
© 2016-2024 GinkCode.com