DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • The Evolution of Scalable and Resilient Container Infrastructure
  • Scaling Microservices With Docker and Kubernetes on Production
  • Can You Run a MariaDB Cluster on a $150 Kubernetes Lab? I Gave It a Shot
  • Building Reliable LLM-Powered Microservices With Kubernetes on AWS

Trending

  • Modern Test Automation With AI (LLM) and Playwright MCP
  • Apple and Anthropic Partner on AI-Powered Vibe-Coding Tool – Public Release TBD
  • Secrets Sprawl and AI: Why Your Non-Human Identities Need Attention Before You Deploy That LLM
  • Distributed Consensus: Paxos vs. Raft and Modern Implementations
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Kubernetes Auditing: Which IAM User Deleted a Namespace?

Kubernetes Auditing: Which IAM User Deleted a Namespace?

Learn how to collect audit logs that are passed through the Kubernetes API server to IBM Log Analysis to check who initiated a request and when they did so.

By 
Vidyasagar (Sarath Chandra) Machupalli FBCS user avatar
Vidyasagar (Sarath Chandra) Machupalli FBCS
DZone Core CORE ·
Feb. 17, 22 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
7.9K Views

Join the DZone community and get the full member experience.

Join For Free

As a cluster administrator, by following the simple steps in this blog post, you should be able to answer questions about Kubernetes audit logs, like who initiated a request to delete a Kubernetes resource? When did it happen? On what did it happen?

Architecture diagram

What Are Audit Logs?

Audit logs allow you to better understand the operations that are initiated by users in your cluster, which can help you troubleshoot issues or report compliance to industry and internal standards.

Although the Kubernetes API server for your cluster is enabled for auditing by default, no auditing data is available until you set up log forwarding. You can forward audit logs for the IBM Cloud Kubernetes Service, the Kubernetes API server, and the worker nodes to a logging instance on IBM Cloud.

Prerequisites

  • Ensure that you completed the steps to forward the Kubernetes API audit logs to Log Analysis.
  • To quickly set up a Kubernetes cluster on VPC, you can use the Terraform scripts provided in the "Multizone Kubernetes and VPC Load Balancer Setup" post.

Query and Decode the Logs

You can always enable and launch logging from your Kubernetes cluster's overview page. By now, you should see the audit logs on the IBM Log Analysis view:

  1. To test, set the context for your cluster without the --adminflag: ibmcloud ks cluster config --cluster <CLUSTER ID or NAME>  
    Note: Using the --admin flag will show the cluster-admin context and may not reveal the IAM user overriding the RBAC.
  2. Create a namespace with the following command: kubectl create namespace test123 
  3. In the Log Analysis UI, enter the following query: verb:create objectRef.name:test123 objectRef.resource:namespaces
    entering query
    So, by now you know which IAM user (who) created the namespace (what) and when was it created. Note: The objectRef.resources is optional and can be any Kubernetes resource (e.g., secrets, configmaps, services, etc.).
  4. Similarly, you can delete the namespace with the command kubectl delete namespace test123. Then, from the audit logs, you can quickly find out who (IAM user) deleted the namespace and at what time. The query to decode who deleted the namespace will be as follows: verb:delete objectRef.name:test123 objectRef.resource:namespaces
    query to decode who deleted the namespace
  5. To create a custom view out of the query:
    • Click "unsaved view" > Save as new view
    • Enter a name for your view
    • Optionally, you can select a category and alert value
    • Click "save view." Your view is listed under your selected category. If you didn't select a category, it will be listed under UNCATEGORIZED.
  6. To add an alert to your custom view, check the add alert to custom view section of IBM Cloud Kubernetes documentation.

Conclusion

Following the steps in the post, you learned what audit logs are, what the audit logs capture, and how to forward and collect the audit logs in IBM Log Analysis to query and decode the logs to understand the operations that are initiated by users in your cluster. 

You can always control user access with IBM Cloud IAM and Kubernetes RBAC. To understand more about Kubernetes auditing and the audit policy, refer to the Kubernetes documentation.

If you have any queries, feel free to reach out to me on Twitter or on LinkedIn. 

Kubernetes

Published at DZone with permission of Vidyasagar (Sarath Chandra) Machupalli FBCS, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • The Evolution of Scalable and Resilient Container Infrastructure
  • Scaling Microservices With Docker and Kubernetes on Production
  • Can You Run a MariaDB Cluster on a $150 Kubernetes Lab? I Gave It a Shot
  • Building Reliable LLM-Powered Microservices With Kubernetes on AWS

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!