This repository has been archived by the owner on Mar 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
this is the implementation of x-client-id header enforcement in Heroic (as opposed to the just-reverted Envoy implementation)
- Loading branch information
Showing
25 changed files
with
262 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
...ion/simple/src/test/java/com/spotify/heroic/aggregation/simple/FilterAggregationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
...on/simple/src/test/java/com/spotify/heroic/aggregation/simple/TdigestAggregationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
heroic-core/src/main/java/com/spotify/heroic/servlet/MandatoryClientIdFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright (c) 2015 Spotify AB. | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package com.spotify.heroic.servlet; | ||
|
||
import com.google.common.base.Strings; | ||
import java.io.IOException; | ||
import javax.servlet.Filter; | ||
import javax.servlet.FilterChain; | ||
import javax.servlet.FilterConfig; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.ServletRequest; | ||
import javax.servlet.ServletResponse; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import javax.ws.rs.core.Response.Status; | ||
|
||
/** | ||
* Rejects anonymous requests. That is, requests to any API endpoint that are | ||
* missing a non-null X-Client-Id HTTP header. | ||
*/ | ||
// Note that this @Suppress has to go here even though it's just for the doFilter | ||
// method, else the JavaDoc for it doesn't render. Weird. | ||
@SuppressWarnings("checkstyle:LineLength") | ||
public class MandatoryClientIdFilter implements Filter { | ||
|
||
public static final String X_CLIENT_ID_HEADER_NAME = "X-Client-Id"; | ||
|
||
@Override | ||
public void init(FilterConfig filterConfig) throws ServletException { /* intentionally empty | ||
*/ } | ||
|
||
/** | ||
* Reject (with a 400) the request, if the X-Client-Id HTTP header is not present | ||
* or is non-null/empty.<p> | ||
* Calling {@link javax.servlet.FilterChain#doFilter} | ||
* effectively "passes" this filter and the next | ||
* filter gets a stab at it. <p> | ||
* Conversely, not calling doFilter halts "happy path" processing altogether | ||
* and that's the mechanism with which we stop anonymous requests.<p> | ||
* Finally, using | ||
* {@link javax.servlet.http.HttpServletResponse#sendError(int, java.lang.String)} to | ||
* return a status message didn't work and instead sent text of "internal error" back | ||
* to the client. | ||
*/ | ||
@Override | ||
public void doFilter( | ||
ServletRequest request, ServletResponse response, FilterChain chain | ||
) throws IOException, ServletException { | ||
if (passesFilter(request)) { | ||
chain.doFilter(request, response); | ||
} else { | ||
var httpResponse = HttpServletResponse.class.cast(response); | ||
httpResponse.setStatus(Status.BAD_REQUEST.getStatusCode()); | ||
} | ||
} | ||
|
||
/** | ||
* Returns true if the HTTP header X-Client-Id is present and non-null and not empty. | ||
* @param request request to pluck X-Client-Id's value from | ||
* @return see above | ||
*/ | ||
public static boolean passesFilter(ServletRequest request) { | ||
var req = HttpServletRequest.class.cast(request); | ||
return !Strings.isNullOrEmpty(req.getHeader(X_CLIENT_ID_HEADER_NAME)); | ||
} | ||
|
||
@Override | ||
public void destroy() { /* intentionally empty */ } | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.