wso2con usa 2017: building an effective api architecture

28
WSO2 API Manager: Building an Effective API Architecture Nuwan Dias Architect WSO2

Upload: wso2-inc

Post on 22-Jan-2018

1.264 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: WSO2Con USA 2017: Building an Effective API Architecture

WSO2APIManager:BuildinganEffectiveAPIArchitecture

NuwanDiasArchitectWSO2

Page 2: WSO2Con USA 2017: Building an Effective API Architecture

KnowingtheComponents

Publisher Store Admin

TrafficManager

GatewayKey

Manager

Nonscalablecomponents

Analytics

Scalablecomponents

Page 3: WSO2Con USA 2017: Building an Effective API Architecture

UnderstandingtheStorage

StorageTypes

• RegistryDatabase-StoresAPIMetaData,TenantKeyStores,Documents,Tags

• APIManagerDatabase-StoresAPIRuntimeData,ApplicationData,TokenData,etc.

• PermissionsDatabase-Storesroletopermissionsandusertopermissionsmappings.

• AnalyticsSummaryDatabase-StoreAPI/Applicationusagesummary.

Page 4: WSO2Con USA 2017: Building an Effective API Architecture

UnderstandingtheStorageContd…

Component Readsonlyfrom Writesto

Publisher PermissionsDB,AnalyticsDB Registry,APIMDB

Store PermissionsDB,AnalyticsDB,Registry

APIMDB

KeyManager PermissionsDB,APIMDB,Registry

TrafficManager PermissionsDB

Page 5: WSO2Con USA 2017: Building an Effective API Architecture

CreatinganAPI

Publisher Store

APIManagerDB(RuntimeData)

RegistryDB(MetaData)

Page 6: WSO2Con USA 2017: Building an Effective API Architecture

PublishinganAPILANDMZ

PublisherGatewayManagerGatewayWorker

GatewayWorker

SecureWebServiceCall

Store

Page 7: WSO2Con USA 2017: Building an Effective API Architecture

PublishinganAPILANDMZ

PublisherGatewayManagerGatewayWorker

GatewayWorker

SecureWebServiceCall

Store

Page 8: WSO2Con USA 2017: Building an Effective API Architecture

API:Therunnableartifact<api name="nuwan--Petstore" context="/petstore/1.0.0" version="1.0.0" version-type="context">

<resource methods="POST PUT" url-mapping="/pet"> …………………………..

<resource methods="DELETE PUT GET" uri-template="/user/{username}"> …………………………..

<handlers> <handler class="org.wso2.carbon.apimgt.gateway.handlers.security.APIAuthenticationHandler">

……………………………

Page 9: WSO2Con USA 2017: Building an Effective API Architecture

API:Thehandlerflow<handlers> <handler class="org.wso2.carbon.apimgt.gateway.handlers.common.APIMgtLatencyStatsHandler"/> <handler class="org.wso2.carbon.apimgt.gateway.handlers.security.CORSRequestHandler"> <property name="apiImplementationType" value="ENDPOINT"/> </handler> <handler class="org.wso2.carbon.apimgt.gateway.handlers.security.APIAuthenticationHandler"/> <handler class="org.wso2.carbon.apimgt.gateway.handlers.throttling.ThrottleHandler"/> <handler class="org.wso2.carbon.apimgt.gateway.handlers.analytics.APIMgtUsageHandler"/> <handler class="org.wso2.carbon.apimgt.gateway.handlers.ext.APIManagerExtensionHandler"/> </handlers>

Page 10: WSO2Con USA 2017: Building an Effective API Architecture

APISecurity

SecurityValidation

APIGateway

ApplicationUser

KeyServer

Page 11: WSO2Con USA 2017: Building an Effective API Architecture

OAuth2.0Grants-ClientCredentials

ImageCredits:PrabathSiriwardena

Page 12: WSO2Con USA 2017: Building an Effective API Architecture

OAuth2.0Grants-ResourceOwnerPassword

ImageCredits:PrabathSiriwardena

Page 13: WSO2Con USA 2017: Building an Effective API Architecture

OAuth2.0Grants-AuthorizationCode

ImageCredits:PrabathSiriwardena

Page 14: WSO2Con USA 2017: Building an Effective API Architecture

OAuth2.0Grants-Implicit

ImageCredits:PrabathSiriwardena

http://callback/#access_token=car292msdjtuis92lla

Page 15: WSO2Con USA 2017: Building an Effective API Architecture

TheRoleoftheAuthorization/KeyServer

POST/register

GET,PUT,DELETE/register/{client_id}

POST/introspection

POST/token

POST/revoke

APIStore

ResourceServer(Gateway)

Authorization/KeyServer

Authentication

Authorization

ClientRegistration

ClientManagement

Introspection

Revocation

TokenManagement

Federation

Page 16: WSO2Con USA 2017: Building an Effective API Architecture

TrafficManagementArchitecture

Gateway GatewayPolicy

Designer

RequestEvent

ThrottleEvent

ThrottlingPolicies

TrafficManager

Page 17: WSO2Con USA 2017: Building an Effective API Architecture

TrafficManagerScalability

• TheTrafficManagerdoesnotscale• AsingleTrafficManagercanhandleupto10Gatewaysat

maximumcapacity• Ifadeploymentconsistsofmorethan10Gateways,theGateways

shouldbedividedintogroupsofclustersof10nodeseach,having1trafficmanagerpergroup.

Page 18: WSO2Con USA 2017: Building an Effective API Architecture

AnalyticsArchitecture

Gateway Admin

Publisher/Store

REST/h

ttp

RawEventsStorage(BigData)

ProcessedData(Summary)

Page 19: WSO2Con USA 2017: Building an Effective API Architecture

API:StagesvsEnvironments-Stages

Production

Staging

Dev

Back-EndSystemsData

Runtime

Useappropriatetooling/processesforthepromotion/demotionofartifacts

Page 20: WSO2Con USA 2017: Building an Effective API Architecture

API:StagesvsEnvironments-Environments

Gateway(External)

Production

Gateway(Internal)

KeyManager(External)

KeyManager(Internal)

Publisher

Store

Page 21: WSO2Con USA 2017: Building an Effective API Architecture

API:StagesvsEnvironmentsStage Environment

RepresentsastateofanAPI RepresentstheexecutionruntimeofanAPIinagivenstate

AnAPImaygothroughmodificationswhentransferringbetweenstages

TheAPIDefinitionisfixedacrossenvironments

Shouldn’tsharedatabetweenstages Maysharedataacrossenvironments

OwnershipoftheAPI/datamaychangeacrossstages

OwnershipoftheAPI/dataremainssameacrossallenvironments

Page 22: WSO2Con USA 2017: Building an Effective API Architecture

RegionalGateways-DatabaseSyncPatternUS-East

US-West

Load-Balancer

Gateway

Gateway

KeyManager

KeyManager

SyncTablesSelectively

Page 23: WSO2Con USA 2017: Building an Effective API Architecture

RegionalGateways-TokenPrefixPatternUS-East

US-West

Load-Balancer

Gateway

Gateway

KeyManager

KeyManager

Createtokenwithprefix“EAST”

Createtokenwithprefix“WEST”

Validatetokenprefix“WEST”

Validatetokenprefix“EAST”

Page 24: WSO2Con USA 2017: Building an Effective API Architecture

RegionalGateways-TokenPrefixPattern

public class CustomTokenGenerator extends OauthTokenIssuerImpl {

@Overridepublic String accessToken(OAuthTokenReqMessageContext tokReqMsgCtx) throws OAuthSystemException { String regionID = System.getProperty(REGION_ID); if(log.isDebugEnabled()){ log.debug("Region ID = " + regionID); } String accessToken = UUID.randomUUID().toString(); return regionID != null ? regionID + accessToken : accessToken;}

Page 25: WSO2Con USA 2017: Building an Effective API Architecture

RegionalGateways-TokenPrefixPatternpublic class RegionValidator extends AbstractHandler {

public boolean handleRequest(MessageContext messageContext) { String regionId = System.getProperty(REGION_ID); if (log.isDebugEnabled()) { log.debug("Region ID = " + regionId); }

. . . . . . . . .

if(bearerToken == null || bearerToken.split(" ")[1].startsWith(regionId)){ //No bearer token provided or the provided bearer token is of the expected region. return true; } handleAuthFailure(messageContext);

return false;

Page 26: WSO2Con USA 2017: Building an Effective API Architecture

APIManager:MultiDatacenterDeployment

TypesofDataCenterDeployments

• SingleMaster,Active-Active• SingleMaster,Active-Passive(DisasterRecovery)• MultiMaster,Active-Active

Page 27: WSO2Con USA 2017: Building an Effective API Architecture

APIManager:MultiDatacenterDeployment

Master MasterorSlave

Page 28: WSO2Con USA 2017: Building an Effective API Architecture

ThankYou!