The API Gateway As Endpoint
Join the DZone community and get the full member experience.Join For Free
the us customs and immigration station at point roberts is a small building set on the edge of the coastal rainforest of washington state. it is the last customs station in a vast western chain strung out along the 49 parallel. i enjoy crossing the border at point roberts. the abrupt change from sprawling canadian suburbs to american rural countryside always appeals to me.
the customs station, despite it’s small size, offers a range of services from granting a visa to simply giving advice about where to find a good deal for gas in point roberts. it’s not simply a gateway controlling access into the us, but a provider of a broad range of services associated with crossing an international boundary.
there exists a similar duality with api gateways. although the common deployment is as a border guard, protecting apis hosted by an organization, an api gateway can also act as an endpoint providing valuable standalone services. nearly all of my customers first purchase securespan gateways to fulfill the role the name implies: that is, an api or service gateway. the border guard deployment pattern is now so commonplace that i no longer need to evangelize it as i did in the early days of layer 7, close to a decade ago. architects recognize this pattern as an accepted best practice for securing and managing apis. but like the point roberts border station, a securespan gateway can also provide services that have nothing to do with access control or transaction confidentiality, but provide value on their own, independent of any apis they may be guarding.
here’s a very simple example illustrating the endpoint pattern using a securespan gateway. normally i might deploy my gateway in front of a web server, acting as an authenticating reverse proxy for my web pages. in this role, the gateway is responsible for access control, ssl management, audit, lightweight load balancing, etc. all classic gateway functions.
but suppose i wanted to use the gateway itself as the web server? in other words, it’s not acting as a gateway, but the server endpoint in itself?
it’s very simple to configure a securespan gateway as an endpoint. you simply create a policy that never routes a request onward to an internal host, but instead acts on the message content internally. i sometimes think of it as an internal loop back mechanism. i’ll build a policy implementing my web site, and add the assertion return template response to requester. i will bind this policy to the gateway url http://localhost:8080/helloworld as shown in the screen snippet below from the securespan management console:
with just one assertion, this is pretty much the simplest policy you can write, and so fitting for the time-honoured hello world example. let’s expand the assertion to examine at what the template actually contains:
pretty plain-vanilla html. the only departure i’ve made from the deliberate austerity of the hello world tradition is to add a time stamp to showcase the use of predefined context variables. there are dozens of context variables that are automatically set as the gateway processes a transaction (regardless of whether it’s actually being a gateway or an endpoint—remember we consider this just a policy implementation pattern, not a different capability). context variables cover everything from accessing individual fields in the x509 certificate used for client-side ssl authentication to storing the ip address of a request sender. and of course, you can set your own context variables at any time within a policy.
just to be complete, here’s what happens when i point my browser at the gateway-as-endpoint:
now, before you think i’ve gone mad, i am not advocating that you deploy a web site like this; there are much better tools for that purpose. but the point i’m making is that there are legitimate endpoint services that do indeed lend themselves to implementation on a gateway. these are just a little more complicated than what i’ve shown here, but nevertheless simple to implement using the declarative policy language in securespan. for example:
- signing services: in the notary pattern, a gateway with an on-board hardware security module (hsm) responsible for protecting key material can easily provide authoritative signing services for all kinds of data, from xml documents to arbitrary text.
- encryption services: same idea as signing, with the goal to avoid insecure proliferation of keys.
- validation services: ensure data conforms to a particular schema.
- threat detection services: scan content for sql injection, cross site scripting (xss), xml threats, or custom threat signatures.
- security token services (sts): issue security tokens like saml or oauth tokens. validate or exchange tokens.
- centralized session or caching management: cache frequently used data items according to a scheme that is tuned to your application.
- policy decision point (pdp) services: receive and act on samlp requests.
- xacml services: act as a centralized xacml engine providing authorization services.
the list above is by no means exclusive; however, at layer 7 we’ve implemented all of these at one time or another using securespan gateways. it’s an important design point for us that the only real difference between a gateway and an endpoint is how you define your policy.
Published at DZone with permission of Scott Morrison . See the original article here.
Opinions expressed by DZone contributors are their own.