SlideShare a Scribd company logo
1 of 21
All contents © MuleSoft, LLC
SEGURIDAD FUERTE COMO
EL VINAGRE DE JEREZ.
POLÍTICAS DE SEGURIDAD
EN API MANAGER
27 de Octubre 2022
NTTDATA. Paseo de la Castellana 77, planta 12 (salas de 6 a 9)
Meetup Mulesoft – API Manager demo
Octubre 2022
All contents © MuleSoft, LLC
API Management
Fuente: What is API Management? | MuleSoft
API management is the process of designing,
publishing, documenting and analyzing APIs in a
secure environment. Through an API
management solution, an organization can
guarantee that both the public and internal APIs
they create are consumable and secure.
All contents © MuleSoft, LLC
API GATEWAY
API MANAGER
API PORTAL
Componentes
DESCUBRIMIENTO
EJECUCIÓN
GESTIÓN
All contents © MuleSoft, LLC
MULE GATEWAY FLEX GATEWAY
MULE RUNTIME
API GATEWAY API GATEWAY
API
MANAGE
R
API
MANAGER
SERVICE MESH
MICRO
SIDECAR
API GATEWAY
API
MANAGER
CONSUMIDORES
BACKEND/MICRO/API
MODO CONECTADO
All contents © MuleSoft, LLC
MULE GATEWAY DETAIL
All contents © MuleSoft, LLC
FLEX
GATEWAY
MULE
GATEWAY
SERVICE
MESH
Basic Authentication: LDAP
✓ ✓ ✓
Allows access based on the basic authorization mechanism, with user-
password defined on LDAP
Basic Authentication: Simple ✓ ✓ ✓
Allows access based on the basic authorization mechanism, with a single
user-password
Client ID Enforcement ✓ ✓ ✓ Allows access only to authorized client applications
Cross-Origin Resource Sharing (CORS) ✓ ✓ Enables access to resources residing in external domains
Detokenization ✓ (*) Returns a tokenized value to its original value
Header Injection ✓ ✓ Adds headers to a request or a response
Header Removal ✓ ✓ Removes headers from a request or a response
HTTP Caching ✓ ✓ Caches HTTP responses from an API implementation
IP Allowlist ✓ ✓ Allows a list or range of specified IP addresses to request access
IP Blocklist ✓ ✓
Blocks a single IP address or a range of IP addresses from accessing an API
endpoint
JSON Threat Protection ✓ Protects against malicious JSON in API requests
JWT Validation ✓ ✓ ✓ Validates a JWT
Message Logging
✓ ✓
Logs custom messages using information from incoming requests,
responses from the backend, or information from other policies applied to the
same API endpoint
OAuth 2.0 Access Token Enforcement Using Mule OAuth
Provider
✓ Allows access only to authorized client applications
OpenAM OAuth 2.0 Token Enforcement ✓ Allows access only to authorized client applications
OpenID Connect Access Token Enforcement ✓ ✓ ✓ Allows access only to authorized client applications
PingFederate OAuth 2.0 Token Enforcement ✓ Allows access only to authorized client applications
Rate Limiting ✓ ✓ ✓
Monitors access to an API by defining the maximum number of requests
processed within a period of time
Rate Limiting: SLA-based ✓ ✓ ✓
Monitors access to an API by defining the maximum number of requests
processed within a timespan, based on SLAs
Spike Control ✓ ✓ Regulates API traffic
Transport Layer Security (TLS) ✓ Enables HTTPS
Tokenization ✓ (*) Transforms sensitive data into a nonsensitive equivalent, named token
(*) Solo en Runtime Fabric
All contents © MuleSoft, LLC
Felipe Pérez González
Technology and Advanced Solutions | Digital Architecture
Expert Architect
felipe.perez.gonzalez@nttdata.com | M: +34 616694123
MuleSoft Custom Policies – Mule 4
All contents © MuleSoft, LLC
Agenda
9
1. Introduction
2. Custom Policy structure
3. Custom Policy modes
4. YAML configuration file
5. Flow execution order
6. Development
7. Deployment into Exchange
8. Demo
9. Highlights
10. References
All contents © MuleSoft, LLC
1. Introduction
10
¿What is a Custom Policy?
● Is a policy that we can add to the runtime to extend
the functionality of Mule applications.
● Is a policy that we can apply to the Mule application
at the runtime level in CloudHub.
● Is a policy that is used to apply functionality to
requirements not covered by out-of-the-box Mule
policies, extending its functionality or defining new
ones.
All contents © MuleSoft, LLC
2. Custom Policy structure
11
Basic XML structure
● <http-policy:proxy name=“{{{policyId}}}-custom-policy”>
 Indicates the policy definition beginning of the logic to
execute in a custom policy.
● <http-policy:source> or <http-policy:operation> 
Indicates the policy definition execution model that will
follow the implementation of the custom policy (source or
operation)
● <http-policy:execute-next/>  Indicates at which point
of the policy definition implementation should jump to the
Mule application flow or when the "http request" call is
made, depending on the execution model.
All contents © MuleSoft, LLC
Source Policies
● The implementation executed before and after the API Mule Application implementation
flow.
● The changes over the Mule messages will only be propagated if they are made “after”
the <http-policy:execute-next/>.
Operation Policies
● The implementation executed before and after an “http:request” inside the API Mule
Application implementation flow.
● The changes over the Mule messages will only be propagated if they are made “before”
the <http-policy:execute-next/>.
Propagation can also be enabled using the attribute
propagateMessageTransformations=“true” in the policy definition execution
model (source or operation), independently of the location of the Mule messages
made.
3. Custom Policy modes
12
Source Policies VS Operation Policies
All contents © MuleSoft, LLC
● id: Unique ID within your organization of the policy.
Mandatory
● name: User friendly name that is used for displaying the
policy name in API Manager’s UI. Mandatory
● supportedPoliciesVersion: Deprecated property. Value
should be set to ‘>=v1’ for now. Mandatory
● description: Description of what the policy does. Also
used in API Manager’s UI. Mandatory
● category: Category to which the policy belongs. Used to
group and filter policies in API Manager’s UI, any String
value is valid. Mandatory
● violationCategory: Deprecated property. Value should
be set to ‘system’. Mandatory
4. YAML configuration file
13
Custom Policy YAML configuration file structure
● type: Value used by the Edge to show metrics about
different types of policy violations. Mandatory
● resourceLevelSupportted: Whether resource level
pointcuts should be enabled when applying the policy.
Mandatory
● standalone: Deprecated property. Value should be set to
‘true’. Mandatory
● identityManagment: Whether policy requires information
about an identity management that is configured to the
API’s Organization. Optional
● configuration: Where the policy parameters are defined.
Every parameter listed here will be rendered as an
expected user input in API Manager’s UI. It expects an
array of values. Mandatory
All contents © MuleSoft, LLC
● propertyName: Internal name of the parameter. Must be unique
within the policy.
● name: User friendly name of the parameter. Used for displaying in
API Manager’s UI.
● description: Description of the parameter. Also, used for
displaying in API Manager’s UI.
● type: Type of the parameter.
● defaultValue: Default value for the parameter.
● optional: Whether is mandatory for the user to enter this value or
not.
● sensitive: Whether this property should be masked when entering
in API Manager’s UI.
● allowMultiple: Whether multiple values should be allowed for this
parameter.
4. YAML configuration file
14
Custom Policy YAML configuration file policy parameter’s structure
Parameter types
● string: Any string expected.
● expression: A DataWeave expression
starting with #[ and finished with ] is expected.
● boolean: true or false.
● int: A number is expected. This type requires
additional properties:
minimumValue: Minimum value allowed for
the parameter.
maximumValue: Maximum value allowed
for the parameter.
● radio: One value of a group of options. This
type requires additional properties:
options:
- name: Name for displaying in the UI
value: internal value used in the policy
● keyvalues: Collection of Key-Value pairs.
All contents © MuleSoft, LLC
Policy A has order 1 and Policy B has order 2.
5. Flow execution order
15
Source Policy VS Operation Policy
<http-policy:proxy name="policy-A">
<http-policy:source>
<A1 />
<http-policy:execute-next/> <!-- API Flow
-->
<A2 />
</http-policy:source>
</http-policy:proxy>
<http-policy:proxy name="policy-B">
<http-policy:operation>
<B1 />
<http-policy:execute-next/> <!-- API Flow
-->
<B2 />
</http-policy:operation>
</http-policy:proxy>
API Invoke > Listener > A1 > API Flow > B1 > HTTP Request > B2 > API Flow > A2 > API Response
A1 B1 B2
A2
API Invoke
API Response
All contents © MuleSoft, LLC
mvn -Parchetype-repository archetype:generate 
-DarchetypeGroupId=org.mule.tools 
-DarchetypeArtifactId=api-gateway-custom-policy-archetype

-DarchetypeVersion=1.2.0 
-DgroupId=${orgId} 
-DartifactId=${policyName} 
-Dversion=0.0.1-SNAPSHOT 
-Dpackage=mule-policy
6. Development
16
Create Custom Policy – Maven Archetype
● Maven Archetype: Is the easiest way to generate a custom policy. Needs the “.m2/settings.xml” of maven well
configured.
It generates a basic policy that sets the returned HTTP Response payload to a “Hello World!”
message.
Data set-up:
● ${orgId}: with the Anypoint Platform Organization Id where
the policy will be uploaded.
● ${policyName}: with the desired name for the custom
policy.
● policyDescription: A brief description of your policy.
● policyName: The identifier name of your policy.
Project structure
● pom.xml:
o groupId: the organization ID used in the archetype.
o mule-policy: the packaging mode for the plugin.
o distributionManagement: pointing to user’s
Exchange.
o mule-maven-plugin: to package the policy into a jar.
o maven-deploy-plugin: to deploy the jar and the
YAML in Exchange.
● mule-artifact.json: exists for the mule-maven-plugin.
This is the same file you need for Mule applications.
● my-custom-policy.yaml: renders the policy
configuration UI. If this file is not provided, the policy
won’t be able to be applied through API Platform’s UI.
● template.xml: where the logic of the policy and Mule
configuration is defined. It could handle any “mule-
application” logic.
All contents © MuleSoft, LLC
6. Development
17
HandleBars
● HandleBars are a templating engine for resolving the configurable parameters of the policy in the YAML configuration
file and implementing semantic logic, such as conditionals in the custom policy logic.
● Each policy parameter defined in a YAML configuration file can be referenced from the policy logic implementation
using curly brackets.
● Simple primitive types (String, Expression, Radio, Int, and Boolean) can be referenced as: {{{myproperty}}}
● Complex types (Keyvalues) can have inner propertie that can be referenced as: {{{keyvalue.key}}} and
{{{keyvalue.value}}}
● The reserved HandleBars properties that can be referenced are:
o {{{policyId}}}: id of the policy, useful for logging or naming a policy
o {{{isWsdlEndpoint}}}: indicates whether the API where the policy is being applied is a WSDL API.
All contents © MuleSoft, LLC
7. Deployment into Exchange
18
Maven Configuration
The deployment into Exchange as an Asset to manage the policy and assign
it into any API Intance in the API Manager is as simple as launch the following
Maven command: “mvn clean package deploy”.
● Exchange Contributors role in your organization to upload the Custom
Policy as an Asset in Exchange.
● pom.xml: Needs to get configured the following parameters:
o <groupId>  Your organization Id.
o <packaging>  “mule-policy”.
o <properties>  “exchange.url” and “mule.maven.plugin.version”.
o <repository>  The exchange server repository of your organization.
o <distributionManagement>  The exchange server as the distribution
management repository.
o <build> <plugins>
 Mule Maven plugin: Verifies the correct policy package.
 Maven Deploy plugin: Uploads the policy JAR and YAML files to
Exchange.
o <pluginRepositories>  Build plugins repository.
● .m2 > settings.xml: Your Exchange credentials.
All contents © MuleSoft, LLC
9. Highlights
19
Tips and Learned Lessons
● A Mule 4 Custom Policy could behave with small changes as a Mule Application.
● The same policy could have both custom policy modes in the logic implementation.
● Always update the “pom.xml” version for a new asset, do not delete the previous uploaded asset in Exchange and
uploaded again with the same version.
● Class isolation:
o Any plugin, library, or resource visible to the application is also visible to any policy applied to that application.
o A policy can define any number of variables that can be accessible only between policy blocks.
 A variable defined in a “http-policy:source” block is available in a subsequent “http-policy:operation” block in the
same policy. They are not available to other polices and to the application.
o If a policy and an application use the same dependency but with different versions, the application’s dependency
version will be used by the policy.
 Always exclude the “mule-http-connector” to avoid inconsistency between versions.
 To uses some custom code (Java, Python, Groovy …) encapsulate it in a custom component and upload it to
Exchange. Then import this custom code component in the custom policy to avoid incompatibilities with the
Applications.
● The “mule-artifact.json > minMuleVersion” property should not be more than 2 minor version of difference with the
runtime version.
● There is no need to configure the pointcut element in Mule 4, this information about the API instance, method and/or
resource on which the custom policy operates is provided by API Manager when a policy is applied.
o Each custom policy is treated independently, even when there are several custom policies of the same asset
applied to the same instance of an API, but to different methods and/or resources.
All contents © MuleSoft, LLC
10. References
20
Some bullets of interest
● HTTP Policy Transform Extension: simplifies the modification of HTTP requests and responses that go through the
different policies.
o Add Headers Operations
 Add Request Headers
 Add Request Headers List
 Add Response Headers
 Add Response Headers List
o Remove Headers
o Set Response
o Set Request
● Caching in a Custom Policy for Mule 4: provides the cache for your custom policy, thus avoiding making external
calls multiple times. It is share with the Mule Application. Is only for CloudHub and hybrid applications. Can be used by
multiple policies applied in different APIs running in different instances in CloudHub.
● Authentication (Security Context): can be exposed through the Authentication object within the Security context
object, using the SDK Mule extension (Authentication Handler). It will be available to other policies and to the
application. Can be accessed using DataWeave
o #[authentication.principal]
o #[authentication.password]
o #[authentication.properties.someProperty]
All contents © MuleSoft, LLC
Thank you
www.mulesoft.com

More Related Content

Similar to [Madrid-Meetup Octubre 22] Seguridad fuerte como el vinagre de Jerez. Políticas de Seguridad en API Manager

Similar to [Madrid-Meetup Octubre 22] Seguridad fuerte como el vinagre de Jerez. Políticas de Seguridad en API Manager (20)

Meet up slides_mumbai_21032020_final
Meet up slides_mumbai_21032020_finalMeet up slides_mumbai_21032020_final
Meet up slides_mumbai_21032020_final
 
Engineering Student MuleSoft Meetup#3 - API Implementation using APIKIT route...
Engineering Student MuleSoft Meetup#3 - API Implementation using APIKIT route...Engineering Student MuleSoft Meetup#3 - API Implementation using APIKIT route...
Engineering Student MuleSoft Meetup#3 - API Implementation using APIKIT route...
 
Warsaw MuleSoft Meetup #7 - custom policy
Warsaw MuleSoft Meetup #7 - custom policyWarsaw MuleSoft Meetup #7 - custom policy
Warsaw MuleSoft Meetup #7 - custom policy
 
Handling NFRs for the API through OoTB API policies Part-1 | MuleSoft Mysore ...
Handling NFRs for the API through OoTB API policies Part-1 | MuleSoft Mysore ...Handling NFRs for the API through OoTB API policies Part-1 | MuleSoft Mysore ...
Handling NFRs for the API through OoTB API policies Part-1 | MuleSoft Mysore ...
 
Baltimore jan2019 mule4
Baltimore jan2019 mule4Baltimore jan2019 mule4
Baltimore jan2019 mule4
 
Mule soft meetup_indonesia_june2020
Mule soft meetup_indonesia_june2020Mule soft meetup_indonesia_june2020
Mule soft meetup_indonesia_june2020
 
MuleSoft Surat Virtual Meetup#3 - Anypoint Custom Policies, API Manager (Prox...
MuleSoft Surat Virtual Meetup#3 - Anypoint Custom Policies, API Manager (Prox...MuleSoft Surat Virtual Meetup#3 - Anypoint Custom Policies, API Manager (Prox...
MuleSoft Surat Virtual Meetup#3 - Anypoint Custom Policies, API Manager (Prox...
 
MuleSoft Surat Virtual Meetup#25 - Anypoint Platform Features and Capabilitie...
MuleSoft Surat Virtual Meetup#25 - Anypoint Platform Features and Capabilitie...MuleSoft Surat Virtual Meetup#25 - Anypoint Platform Features and Capabilitie...
MuleSoft Surat Virtual Meetup#25 - Anypoint Platform Features and Capabilitie...
 
Federation Evolved: How Cloud, Mobile & APIs Change the Way We Broker Identity
Federation Evolved: How Cloud, Mobile & APIs Change the Way We Broker IdentityFederation Evolved: How Cloud, Mobile & APIs Change the Way We Broker Identity
Federation Evolved: How Cloud, Mobile & APIs Change the Way We Broker Identity
 
Practical Data Mesh: Building Decentralized Data Architectures with Event Stream
Practical Data Mesh: Building Decentralized Data Architectures with Event StreamPractical Data Mesh: Building Decentralized Data Architectures with Event Stream
Practical Data Mesh: Building Decentralized Data Architectures with Event Stream
 
Practical Data Mesh: Building Decentralized Data Architectures with Event Str...
Practical Data Mesh: Building Decentralized Data Architectures with Event Str...Practical Data Mesh: Building Decentralized Data Architectures with Event Str...
Practical Data Mesh: Building Decentralized Data Architectures with Event Str...
 
Virtual meetup - Exploring the Runtime Fabric deployment model
Virtual meetup - Exploring the Runtime Fabric deployment modelVirtual meetup - Exploring the Runtime Fabric deployment model
Virtual meetup - Exploring the Runtime Fabric deployment model
 
apidays LIVE Australia 2020 - Data with a Mission by Matt McLarty
apidays LIVE Australia 2020 -  Data with a Mission by Matt McLarty apidays LIVE Australia 2020 -  Data with a Mission by Matt McLarty
apidays LIVE Australia 2020 - Data with a Mission by Matt McLarty
 
apidays LIVE Paris - Data with a mission: a COVID-19 API case study by Matt M...
apidays LIVE Paris - Data with a mission: a COVID-19 API case study by Matt M...apidays LIVE Paris - Data with a mission: a COVID-19 API case study by Matt M...
apidays LIVE Paris - Data with a mission: a COVID-19 API case study by Matt M...
 
Azure API Manegement Introduction and Integeration with BizTalk
Azure API Manegement Introduction and Integeration with BizTalkAzure API Manegement Introduction and Integeration with BizTalk
Azure API Manegement Introduction and Integeration with BizTalk
 
EduID Mobile App - Use-Cases, Concepts and Implementation
EduID Mobile App - Use-Cases, Concepts and ImplementationEduID Mobile App - Use-Cases, Concepts and Implementation
EduID Mobile App - Use-Cases, Concepts and Implementation
 
Uncover the Flex Gateway with a Demonstration (1).pdf
Uncover the Flex Gateway with a Demonstration (1).pdfUncover the Flex Gateway with a Demonstration (1).pdf
Uncover the Flex Gateway with a Demonstration (1).pdf
 
Uncover the Flex Gateway with a Demonstration (1).pdf
Uncover the Flex Gateway with a Demonstration (1).pdfUncover the Flex Gateway with a Demonstration (1).pdf
Uncover the Flex Gateway with a Demonstration (1).pdf
 
Mule Meetup Calgary- API Governance & Conformance.pdf
Mule Meetup Calgary- API Governance & Conformance.pdfMule Meetup Calgary- API Governance & Conformance.pdf
Mule Meetup Calgary- API Governance & Conformance.pdf
 
Gravitee API Management - Ahmet AYDIN
 Gravitee API Management  -  Ahmet AYDIN Gravitee API Management  -  Ahmet AYDIN
Gravitee API Management - Ahmet AYDIN
 

Recently uploaded

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Recently uploaded (20)

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 

[Madrid-Meetup Octubre 22] Seguridad fuerte como el vinagre de Jerez. Políticas de Seguridad en API Manager

  • 1. All contents © MuleSoft, LLC SEGURIDAD FUERTE COMO EL VINAGRE DE JEREZ. POLÍTICAS DE SEGURIDAD EN API MANAGER 27 de Octubre 2022 NTTDATA. Paseo de la Castellana 77, planta 12 (salas de 6 a 9)
  • 2. Meetup Mulesoft – API Manager demo Octubre 2022
  • 3. All contents © MuleSoft, LLC API Management Fuente: What is API Management? | MuleSoft API management is the process of designing, publishing, documenting and analyzing APIs in a secure environment. Through an API management solution, an organization can guarantee that both the public and internal APIs they create are consumable and secure.
  • 4. All contents © MuleSoft, LLC API GATEWAY API MANAGER API PORTAL Componentes DESCUBRIMIENTO EJECUCIÓN GESTIÓN
  • 5. All contents © MuleSoft, LLC MULE GATEWAY FLEX GATEWAY MULE RUNTIME API GATEWAY API GATEWAY API MANAGE R API MANAGER SERVICE MESH MICRO SIDECAR API GATEWAY API MANAGER CONSUMIDORES BACKEND/MICRO/API MODO CONECTADO
  • 6. All contents © MuleSoft, LLC MULE GATEWAY DETAIL
  • 7. All contents © MuleSoft, LLC FLEX GATEWAY MULE GATEWAY SERVICE MESH Basic Authentication: LDAP ✓ ✓ ✓ Allows access based on the basic authorization mechanism, with user- password defined on LDAP Basic Authentication: Simple ✓ ✓ ✓ Allows access based on the basic authorization mechanism, with a single user-password Client ID Enforcement ✓ ✓ ✓ Allows access only to authorized client applications Cross-Origin Resource Sharing (CORS) ✓ ✓ Enables access to resources residing in external domains Detokenization ✓ (*) Returns a tokenized value to its original value Header Injection ✓ ✓ Adds headers to a request or a response Header Removal ✓ ✓ Removes headers from a request or a response HTTP Caching ✓ ✓ Caches HTTP responses from an API implementation IP Allowlist ✓ ✓ Allows a list or range of specified IP addresses to request access IP Blocklist ✓ ✓ Blocks a single IP address or a range of IP addresses from accessing an API endpoint JSON Threat Protection ✓ Protects against malicious JSON in API requests JWT Validation ✓ ✓ ✓ Validates a JWT Message Logging ✓ ✓ Logs custom messages using information from incoming requests, responses from the backend, or information from other policies applied to the same API endpoint OAuth 2.0 Access Token Enforcement Using Mule OAuth Provider ✓ Allows access only to authorized client applications OpenAM OAuth 2.0 Token Enforcement ✓ Allows access only to authorized client applications OpenID Connect Access Token Enforcement ✓ ✓ ✓ Allows access only to authorized client applications PingFederate OAuth 2.0 Token Enforcement ✓ Allows access only to authorized client applications Rate Limiting ✓ ✓ ✓ Monitors access to an API by defining the maximum number of requests processed within a period of time Rate Limiting: SLA-based ✓ ✓ ✓ Monitors access to an API by defining the maximum number of requests processed within a timespan, based on SLAs Spike Control ✓ ✓ Regulates API traffic Transport Layer Security (TLS) ✓ Enables HTTPS Tokenization ✓ (*) Transforms sensitive data into a nonsensitive equivalent, named token (*) Solo en Runtime Fabric
  • 8. All contents © MuleSoft, LLC Felipe Pérez González Technology and Advanced Solutions | Digital Architecture Expert Architect felipe.perez.gonzalez@nttdata.com | M: +34 616694123 MuleSoft Custom Policies – Mule 4
  • 9. All contents © MuleSoft, LLC Agenda 9 1. Introduction 2. Custom Policy structure 3. Custom Policy modes 4. YAML configuration file 5. Flow execution order 6. Development 7. Deployment into Exchange 8. Demo 9. Highlights 10. References
  • 10. All contents © MuleSoft, LLC 1. Introduction 10 ¿What is a Custom Policy? ● Is a policy that we can add to the runtime to extend the functionality of Mule applications. ● Is a policy that we can apply to the Mule application at the runtime level in CloudHub. ● Is a policy that is used to apply functionality to requirements not covered by out-of-the-box Mule policies, extending its functionality or defining new ones.
  • 11. All contents © MuleSoft, LLC 2. Custom Policy structure 11 Basic XML structure ● <http-policy:proxy name=“{{{policyId}}}-custom-policy”>  Indicates the policy definition beginning of the logic to execute in a custom policy. ● <http-policy:source> or <http-policy:operation>  Indicates the policy definition execution model that will follow the implementation of the custom policy (source or operation) ● <http-policy:execute-next/>  Indicates at which point of the policy definition implementation should jump to the Mule application flow or when the "http request" call is made, depending on the execution model.
  • 12. All contents © MuleSoft, LLC Source Policies ● The implementation executed before and after the API Mule Application implementation flow. ● The changes over the Mule messages will only be propagated if they are made “after” the <http-policy:execute-next/>. Operation Policies ● The implementation executed before and after an “http:request” inside the API Mule Application implementation flow. ● The changes over the Mule messages will only be propagated if they are made “before” the <http-policy:execute-next/>. Propagation can also be enabled using the attribute propagateMessageTransformations=“true” in the policy definition execution model (source or operation), independently of the location of the Mule messages made. 3. Custom Policy modes 12 Source Policies VS Operation Policies
  • 13. All contents © MuleSoft, LLC ● id: Unique ID within your organization of the policy. Mandatory ● name: User friendly name that is used for displaying the policy name in API Manager’s UI. Mandatory ● supportedPoliciesVersion: Deprecated property. Value should be set to ‘>=v1’ for now. Mandatory ● description: Description of what the policy does. Also used in API Manager’s UI. Mandatory ● category: Category to which the policy belongs. Used to group and filter policies in API Manager’s UI, any String value is valid. Mandatory ● violationCategory: Deprecated property. Value should be set to ‘system’. Mandatory 4. YAML configuration file 13 Custom Policy YAML configuration file structure ● type: Value used by the Edge to show metrics about different types of policy violations. Mandatory ● resourceLevelSupportted: Whether resource level pointcuts should be enabled when applying the policy. Mandatory ● standalone: Deprecated property. Value should be set to ‘true’. Mandatory ● identityManagment: Whether policy requires information about an identity management that is configured to the API’s Organization. Optional ● configuration: Where the policy parameters are defined. Every parameter listed here will be rendered as an expected user input in API Manager’s UI. It expects an array of values. Mandatory
  • 14. All contents © MuleSoft, LLC ● propertyName: Internal name of the parameter. Must be unique within the policy. ● name: User friendly name of the parameter. Used for displaying in API Manager’s UI. ● description: Description of the parameter. Also, used for displaying in API Manager’s UI. ● type: Type of the parameter. ● defaultValue: Default value for the parameter. ● optional: Whether is mandatory for the user to enter this value or not. ● sensitive: Whether this property should be masked when entering in API Manager’s UI. ● allowMultiple: Whether multiple values should be allowed for this parameter. 4. YAML configuration file 14 Custom Policy YAML configuration file policy parameter’s structure Parameter types ● string: Any string expected. ● expression: A DataWeave expression starting with #[ and finished with ] is expected. ● boolean: true or false. ● int: A number is expected. This type requires additional properties: minimumValue: Minimum value allowed for the parameter. maximumValue: Maximum value allowed for the parameter. ● radio: One value of a group of options. This type requires additional properties: options: - name: Name for displaying in the UI value: internal value used in the policy ● keyvalues: Collection of Key-Value pairs.
  • 15. All contents © MuleSoft, LLC Policy A has order 1 and Policy B has order 2. 5. Flow execution order 15 Source Policy VS Operation Policy <http-policy:proxy name="policy-A"> <http-policy:source> <A1 /> <http-policy:execute-next/> <!-- API Flow --> <A2 /> </http-policy:source> </http-policy:proxy> <http-policy:proxy name="policy-B"> <http-policy:operation> <B1 /> <http-policy:execute-next/> <!-- API Flow --> <B2 /> </http-policy:operation> </http-policy:proxy> API Invoke > Listener > A1 > API Flow > B1 > HTTP Request > B2 > API Flow > A2 > API Response A1 B1 B2 A2 API Invoke API Response
  • 16. All contents © MuleSoft, LLC mvn -Parchetype-repository archetype:generate -DarchetypeGroupId=org.mule.tools -DarchetypeArtifactId=api-gateway-custom-policy-archetype -DarchetypeVersion=1.2.0 -DgroupId=${orgId} -DartifactId=${policyName} -Dversion=0.0.1-SNAPSHOT -Dpackage=mule-policy 6. Development 16 Create Custom Policy – Maven Archetype ● Maven Archetype: Is the easiest way to generate a custom policy. Needs the “.m2/settings.xml” of maven well configured. It generates a basic policy that sets the returned HTTP Response payload to a “Hello World!” message. Data set-up: ● ${orgId}: with the Anypoint Platform Organization Id where the policy will be uploaded. ● ${policyName}: with the desired name for the custom policy. ● policyDescription: A brief description of your policy. ● policyName: The identifier name of your policy. Project structure ● pom.xml: o groupId: the organization ID used in the archetype. o mule-policy: the packaging mode for the plugin. o distributionManagement: pointing to user’s Exchange. o mule-maven-plugin: to package the policy into a jar. o maven-deploy-plugin: to deploy the jar and the YAML in Exchange. ● mule-artifact.json: exists for the mule-maven-plugin. This is the same file you need for Mule applications. ● my-custom-policy.yaml: renders the policy configuration UI. If this file is not provided, the policy won’t be able to be applied through API Platform’s UI. ● template.xml: where the logic of the policy and Mule configuration is defined. It could handle any “mule- application” logic.
  • 17. All contents © MuleSoft, LLC 6. Development 17 HandleBars ● HandleBars are a templating engine for resolving the configurable parameters of the policy in the YAML configuration file and implementing semantic logic, such as conditionals in the custom policy logic. ● Each policy parameter defined in a YAML configuration file can be referenced from the policy logic implementation using curly brackets. ● Simple primitive types (String, Expression, Radio, Int, and Boolean) can be referenced as: {{{myproperty}}} ● Complex types (Keyvalues) can have inner propertie that can be referenced as: {{{keyvalue.key}}} and {{{keyvalue.value}}} ● The reserved HandleBars properties that can be referenced are: o {{{policyId}}}: id of the policy, useful for logging or naming a policy o {{{isWsdlEndpoint}}}: indicates whether the API where the policy is being applied is a WSDL API.
  • 18. All contents © MuleSoft, LLC 7. Deployment into Exchange 18 Maven Configuration The deployment into Exchange as an Asset to manage the policy and assign it into any API Intance in the API Manager is as simple as launch the following Maven command: “mvn clean package deploy”. ● Exchange Contributors role in your organization to upload the Custom Policy as an Asset in Exchange. ● pom.xml: Needs to get configured the following parameters: o <groupId>  Your organization Id. o <packaging>  “mule-policy”. o <properties>  “exchange.url” and “mule.maven.plugin.version”. o <repository>  The exchange server repository of your organization. o <distributionManagement>  The exchange server as the distribution management repository. o <build> <plugins>  Mule Maven plugin: Verifies the correct policy package.  Maven Deploy plugin: Uploads the policy JAR and YAML files to Exchange. o <pluginRepositories>  Build plugins repository. ● .m2 > settings.xml: Your Exchange credentials.
  • 19. All contents © MuleSoft, LLC 9. Highlights 19 Tips and Learned Lessons ● A Mule 4 Custom Policy could behave with small changes as a Mule Application. ● The same policy could have both custom policy modes in the logic implementation. ● Always update the “pom.xml” version for a new asset, do not delete the previous uploaded asset in Exchange and uploaded again with the same version. ● Class isolation: o Any plugin, library, or resource visible to the application is also visible to any policy applied to that application. o A policy can define any number of variables that can be accessible only between policy blocks.  A variable defined in a “http-policy:source” block is available in a subsequent “http-policy:operation” block in the same policy. They are not available to other polices and to the application. o If a policy and an application use the same dependency but with different versions, the application’s dependency version will be used by the policy.  Always exclude the “mule-http-connector” to avoid inconsistency between versions.  To uses some custom code (Java, Python, Groovy …) encapsulate it in a custom component and upload it to Exchange. Then import this custom code component in the custom policy to avoid incompatibilities with the Applications. ● The “mule-artifact.json > minMuleVersion” property should not be more than 2 minor version of difference with the runtime version. ● There is no need to configure the pointcut element in Mule 4, this information about the API instance, method and/or resource on which the custom policy operates is provided by API Manager when a policy is applied. o Each custom policy is treated independently, even when there are several custom policies of the same asset applied to the same instance of an API, but to different methods and/or resources.
  • 20. All contents © MuleSoft, LLC 10. References 20 Some bullets of interest ● HTTP Policy Transform Extension: simplifies the modification of HTTP requests and responses that go through the different policies. o Add Headers Operations  Add Request Headers  Add Request Headers List  Add Response Headers  Add Response Headers List o Remove Headers o Set Response o Set Request ● Caching in a Custom Policy for Mule 4: provides the cache for your custom policy, thus avoiding making external calls multiple times. It is share with the Mule Application. Is only for CloudHub and hybrid applications. Can be used by multiple policies applied in different APIs running in different instances in CloudHub. ● Authentication (Security Context): can be exposed through the Authentication object within the Security context object, using the SDK Mule extension (Authentication Handler). It will be available to other policies and to the application. Can be accessed using DataWeave o #[authentication.principal] o #[authentication.password] o #[authentication.properties.someProperty]
  • 21. All contents © MuleSoft, LLC Thank you www.mulesoft.com

Editor's Notes

  1. Las políticas le permiten hacer cumplir las normas para ayudar a administrar la seguridad, controlar el tráfico y mejorar la adaptabilidad de sus API. Por ejemplo, una política puede controlar la autenticación, el acceso, el consumo asignado y el acceso al nivel de servicio (SLA). Puede implementar estas regulaciones sin modificar la implementación del código.
  2. ==== Core to this is the API, If you look at the single technology component that has enabled this different approach to be successful, it is leveraging APIs as the standard building blocks and if you take a look at an API, we like to use the analogy of the LEGO,Individual LEGO pieces, each with a very clear and defined purpose or specification, all of which is designed to fit together and serve a specific purpose.they are designed to produced for consumers to be able to use. An API could be anything like looking at a specific order in a system or it could be a Process that is orchestrating the entire inventory and order mgmt process.So APIs can be small services or larger composite services, that could be ultimately discovered and put together to drive reuse. The key though is by using APIs, we can allow for better mgmt and security and have standards enforced by APIs by themselves and this is what allows people to get better discovery and consumption allowing IT in the organization to retain control ====== Key Messages: - APIs are standard building blocks. - Composability allows organizations to go faster and do more than ever before. - APIs are now the business capability that enables you to move fast, be more agile and unlock innovation across your organization, while maintaining security and control. Talk Track: APIs are the building blocks that represent unique business capabilities – like inventory data or order status – that can be composed easily into a connected experience. API-led connectivity and composability allows organizations to go faster and do more than ever before. Why? If various components are wrapped in APIs that can be easily discovered, understood, consumed and secured, they enable different teams across the organization to access data and digital capabilities in a way never before possible, while giving IT the tools to manage and secure them at scale. This allows organizations to roll out new connected experiences faster, now and in the future. That’s what we call ‘API-led connectivity’. Transition: By making it possible to integrate systems and unify data with reusable APIs, we’re seeing organizations accelerate the speed of IT delivery, increase organizational agility, and deliver innovation at scale.
  3. ==== Core to this is the API, If you look at the single technology component that has enabled this different approach to be successful, it is leveraging APIs as the standard building blocks and if you take a look at an API, we like to use the analogy of the LEGO,Individual LEGO pieces, each with a very clear and defined purpose or specification, all of which is designed to fit together and serve a specific purpose.they are designed to produced for consumers to be able to use. An API could be anything like looking at a specific order in a system or it could be a Process that is orchestrating the entire inventory and order mgmt process.So APIs can be small services or larger composite services, that could be ultimately discovered and put together to drive reuse. The key though is by using APIs, we can allow for better mgmt and security and have standards enforced by APIs by themselves and this is what allows people to get better discovery and consumption allowing IT in the organization to retain control ====== Key Messages: - APIs are standard building blocks. - Composability allows organizations to go faster and do more than ever before. - APIs are now the business capability that enables you to move fast, be more agile and unlock innovation across your organization, while maintaining security and control. Talk Track: APIs are the building blocks that represent unique business capabilities – like inventory data or order status – that can be composed easily into a connected experience. API-led connectivity and composability allows organizations to go faster and do more than ever before. Why? If various components are wrapped in APIs that can be easily discovered, understood, consumed and secured, they enable different teams across the organization to access data and digital capabilities in a way never before possible, while giving IT the tools to manage and secure them at scale. This allows organizations to roll out new connected experiences faster, now and in the future. That’s what we call ‘API-led connectivity’. Transition: By making it possible to integrate systems and unify data with reusable APIs, we’re seeing organizations accelerate the speed of IT delivery, increase organizational agility, and deliver innovation at scale.
  4. ==== Core to this is the API, If you look at the single technology component that has enabled this different approach to be successful, it is leveraging APIs as the standard building blocks and if you take a look at an API, we like to use the analogy of the LEGO,Individual LEGO pieces, each with a very clear and defined purpose or specification, all of which is designed to fit together and serve a specific purpose.they are designed to produced for consumers to be able to use. An API could be anything like looking at a specific order in a system or it could be a Process that is orchestrating the entire inventory and order mgmt process.So APIs can be small services or larger composite services, that could be ultimately discovered and put together to drive reuse. The key though is by using APIs, we can allow for better mgmt and security and have standards enforced by APIs by themselves and this is what allows people to get better discovery and consumption allowing IT in the organization to retain control ====== Key Messages: - APIs are standard building blocks. - Composability allows organizations to go faster and do more than ever before. - APIs are now the business capability that enables you to move fast, be more agile and unlock innovation across your organization, while maintaining security and control. Talk Track: APIs are the building blocks that represent unique business capabilities – like inventory data or order status – that can be composed easily into a connected experience. API-led connectivity and composability allows organizations to go faster and do more than ever before. Why? If various components are wrapped in APIs that can be easily discovered, understood, consumed and secured, they enable different teams across the organization to access data and digital capabilities in a way never before possible, while giving IT the tools to manage and secure them at scale. This allows organizations to roll out new connected experiences faster, now and in the future. That’s what we call ‘API-led connectivity’. Transition: By making it possible to integrate systems and unify data with reusable APIs, we’re seeing organizations accelerate the speed of IT delivery, increase organizational agility, and deliver innovation at scale.