Introduction
In our last lesson, you built a complete, responsive API proxy that accepted a webhook request, called the GitHub API, processed the response with Python, and returned a clean, custom result. This was a significant step, but all our API interactions so far have been with public, unauthenticated endpoints. To achieve your goal of automating CI/CD pipelines, you'll need to interact with private repositories, trigger protected build jobs, and manage services that require secure authentication.
This lesson marks our transition into building production-ready, secure workflows. We will tackle the foundational element of security in n8n: credential management. You will learn why hardcoding keys is a risk, how n8n's centralized credential manager solves this, and how to create and use credentials to securely authenticate with third-party services. This knowledge is non-negotiable for the self-hosted, production environment you aim to build.
The Foundation of Secure Automation
Before we interact with any API, it's crucial to establish a secure way to handle secrets like API keys, tokens, and other sensitive credentials. Simply pasting a key into a node's parameter field introduces significant security risks and creates a maintenance nightmare.
n8n provides a robust, centralized system for this. It acts as a secure vault, encrypting your secrets and allowing you to reference them by name throughout your workflows. This means if a key needs to be updated, you change it in one place, and all workflows that use it are automatically updated.

To understand the principles and practicalities of n8n's credential system, the following article provides an excellent overview. It covers the risks of poor management, the types of credentials n8n supports, and the underlying encryption architecture.
n8n Credentials: Managing API Keys and Authentication Securely
This article from OctaveHQ provides a thorough introduction to n8n's credential system, emphasizing production-grade practices.
Please read the following sections to get a comprehensive understanding of n8n's approach to security: Start with Why Credential Management Matters to understand the security and operational risks that a centralized system mitigates. Read Understanding n8n Credential Types to familiarize yourself with the main authentication methods like API Key, OAuth2, and Header Auth. Review Setting Up Credentials Securely for a step-by-step guide to the creation process. Finally, pay close attention to Encryption and Storage Architecture. The section on the N8N_ENCRYPTION_KEY is particularly critical for your goal of self-hosting a production instance.
From Insecure Header to Encrypted Credential
One of the most common authentication methods for APIs, especially in the CI/CD space for tools like Jenkins or custom webhooks, involves passing a token in an HTTP header (e.g., Authorization: Bearer <token> or X-API-Key: <token>).
The following video provides a clear, practical demonstration of a common mistake—placing a token directly in the HTTP Request node's header—and then shows the correct, secure method of creating a generic credential to handle it.
How I connect to ANY API in 2 minutes (N8N and NoCode)
This short video by Simon Scrapes perfectly illustrates the process of securing an API key that would otherwise be exposed in a workflow's header configuration.
Watch from this section of the video. The key actions to observe are: Recognizing that sending the key in the visible header parameters is "really dangerous." Moving from the node's parameters to the Authentication section. Choosing a Generic Credential Type (Header Auth). Creating a new credential, giving it a name, and inputting the header key name (Authorization) and the value (Bearer <key>). Saving the encrypted credential and removing the insecure, plain-text header.
Hands-On: Creating Your First Credential
Now, let's put this into practice. You will create a generic "Header Auth" credential. This type is extremely versatile and will be useful for many of the custom tools and APIs you'll encounter. We will use dummy values for now to focus on the process itself.
Your Task:
- In your n8n instance, navigate to the Credentials section in the left-hand sidebar.
- Click Add credential.
- In the "Search apps" field, type
Header Authand select it. - A dialog will appear for you to configure the new credential.
- Credential Name: Give it a descriptive name that indicates its purpose, e.g.,
My-CI-Service-Key. - Name: This is the name of the HTTP header. Enter
X-Api-Key. - Value: This is the secret token. Enter a dummy value like
s3cr3t-t0k3n-f0r-t3st1ng.
- Credential Name: Give it a descriptive name that indicates its purpose, e.g.,
- Click Save.
That's it. You have now created your first credential. It is securely stored and encrypted within n8n's database, and you can now reference it by the name My-CI-Service-Key in any HTTP Request node across all your workflows. If the token ever changes, you only need to edit this single entry.
Generic vs. Predefined Credentials
In the exercise, you created a "Generic Credential Type." This is a powerful feature for connecting to any API, regardless of whether n8n has a dedicated integration for it. Since you'll be working with specialized CI/CD tools, understanding these generic types is essential.
The following video explains the distinction between n8n's two main categories of credentials and provides a tour of the most common generic authentication methods you'll encounter.
Complete n8n Authentication Mastery in 14 Minutes | All Auth Methods | Complete Guide
This video from FuturMinds clearly explains the different authentication methods available in n8n, focusing on the flexible generic types.
Please watch the following two segments: First, watch Predefined vs. Generic. This explains when to use the service-specific credentials (like 'Google Sheets') versus the generic ones (like 'Header Auth'). Next, watch the detailed breakdown of Generic Auth Types. Pay attention to the explanations for Bearer Auth, Header Auth, and Query Auth, as these are common patterns. You can skim the parts on Basic and Digest auth, which are for older systems.
Conclusion
In this lesson, you've established the cornerstone of secure workflow automation in n8n. You now understand the critical importance of abstracting secrets away from your workflow logic and using n8n's centralized, encrypted credential manager.
Key Takeaways:
- Never hardcode API keys or tokens directly in your nodes.
- n8n's Credential Manager provides a centralized and secure way to store and reuse secrets.
- All credentials are encrypted at rest, and this encryption is protected by the
N8N_ENCRYPTION_KEYin your environment—a critical variable for your self-hosted setup. - n8n supports predefined credentials for common services and highly flexible generic credential types (like Header Auth, Bearer Auth, etc.) for connecting to any API.
You are now equipped to create credentials for simple authentication schemes. In our next lesson, we will build on this foundation to tackle a more advanced, but common, authentication protocol: OAuth2. We will return to our GitHub workflow and configure it to properly authenticate as a GitHub App, a necessary step for accessing private repositories and performing actions on behalf of a user.