How do make an SSL Connection from a Kong serverless function using a client certificate - ssl

I'm trying to create a serverless function for Kong for authentication purposes. I'm required to use a client certificate to authenticate with the remote service that we have to use. I can't seem to get this working and there appears to be no clear documentation on how to do this. I've tried pintsized/lua-resty-http, ngx.socket.tcp(), and luacurl (failed to build) without success. I'm using the newest version of Kong in an Alpine Linux container in case that matters.
What is the best way to do this? Right now I'm considering simply calling curl from within Lua as I know that works, but I was hoping for a better solution that I can do with just Lua/OpenResty.
Thanks.
UPDATE: I just wanted to add, just in case it helps, that I'm already building a new image based on the official Kong one as I had to modify the nginx configuration templates, so installing new software into the container is not an issue.

All,
Apologies for the ugly code, but it looks like a found an answer that works:
require("socket")
local currUrl= "https://some.url/"
local https = require("ssl.https")
local ltn12 = require("ltn12")
local chunks = {}
local body, code, headers, status = https.request{
mode = "client",
url = currUrl,
protocol = "tlsv1_2",
certificate = "/certs/bundle.crt",
key = "/certs/bundle.key",
verify = "none",
sink = ltn12.sink.table(chunks),
}
If someone has a better answer, I'd appreciate it, but it's hard to complain about this one. The main issue is that while this works for a GET request, I'll be wanting to do POSTs to a service in a future and I have no idea how to do it using similar code. I'd like one libary/API that can do any type of REST request.
This blog got me on the right track: http://notebook.kulchenko.com/programming/https-ssl-calls-with-lua-and-luasec

Related

Connecting IntelliJ Idea Servers to GitLab.com: what info is actually needed?

I'm trying to configure IntelliJ IDEA 2017.1.2 in order to get the tasks from a private repository on GitLab.com.
To do that I have to create the corresponding entry in the Servers window.
Now, I don't have the faintest idea about how I should fill the Servers form in IDEA.
What URL I have to use for Server URL ?
What token ?
Any advice? Thx in advance.
UPDATE: Based on the information mentioned in the issue IDEA-193736, the connectivity problem with the new GitLab Issues API (V4) should be fixed when the update 2018.2 is released.
The https://gitlab.com URL didn't work for me as the API URL was updated to V4 on GitLab. So, after some trial and error I was able to make it work by completing the following steps:
Create a Personal Access Token on GitLab (https://gitlab.com/profile/personal_access_tokens) with API and read_user access permissions
In IntelliJ (or Pycharm in my case), the Server URL should be https://gitlab.com/api/v4/issues? (with the question mark at the end)
The token is the Personal Access Token that was generated previously
Also, don't forget to increase the connection timeout to 15000 milliseconds under the Tasks section in the Settings (Settings => Tools => Tasks).
Task Server Screenshot
Hope it helps someone else.
[EDIT] This answer was valid in '17, when it was created. For an up to date anwer, pls see other answers in the thread.
So, here's how to do it.
First of all, go to gitlab.
Access with your data and get a personal access token.
Then, you can configure IntelliJ Idea with the following values:
You can now check all your GitLab's issues directly in Idea, as shown here below.

Spring Config Client - ConfigClientWatch

I am looking at the class ConfigClientWatch in the package package org.springframework.cloud.config.client;
I was expecting that I could use this to poll the server periodically to see if the config had changed and then execute an refresh.
I am not able to get this to work? How does the value
String newState = this.environment.getProperty("config.client.state");
Get updated.
I have not been able to find any documentation on this.
Thanks in Advance
Raghu
Unfortunately, this property is only used by Vault backend. Anyway, there is a thread in the Spring Config's GitHub proposing changes to support other backends such as Git.
If you are using Git-backed configurations, this solution may work for you:
https://github.com/spring-cloud/spring-cloud-config/issues/1378#issuecomment-492073851
Please, upvote the GitHub thread so this feature gets accepted.

Proxy settings in RStudio for third party API access

I'm using RStudio on a server that is behind my company's firewall. I referred to the link here and did the same changes in my RProfile script:
RProfile
http_proxy=http://proxy.dom.com:80
http_proxy_user=user:passwd
I'm trying to access an API (Omniture a.k.a. api.omniture.com) using the package RSiteCatalyst and even though I mentioned the proxy, I'm unable to bypass the firewall. Below is what I do:
library(RSiteCatalyst)
SCAuth('username','shared-secret') # Authentication
And the error that I get
Error in function (type, msg, asError = TRUE) :
Could not resolve host: api.omniture.com
Before going to IT I came here for the StackOverflow gods to help out. Would greatly appreciate it. Thanks.
I think that article has a typo. Can you put the http_proxy lines in your .Renviron rather than your .Rprofile, then restart RStudio? (If that does the job, we'll update the article!)

How to write commit message to svn repository

I am using Apache Jackrabbit Webdav library for svn checkin operation.
I am using MAKActivity method to start the transaction.
But I dont know how to add commit message. Following is the code
RandomStringGenerator rsg = new RandomStringGenerator(32);
String random = rsg.nextString();
String url = getRepoAddress() + "!svn/act/" + random;
MkActivityMethod activityMethod = null;
try
{
activityMethod = new MkActivityMethod(url);
client.executeMethod(activityMethod);
}
catch(Exception e)
{
e.printStackTrace();
}
This code executes successfully but I dont unserstand how to write log message in this.
Any help will be appreciable.
First of all I'd suggest that you not reinvent the wheel that's already been done twice now and instead using a library that knows Subversion's DAV based protocol. Note that while Subversion is mostly WebDAV and DeltaV compatible, it does have non-standard extensions.
To that end I'd point you to JavaHL or SVNKit. JavaHL comes with Subversion and uses JNI to access the Subversion libraries. SVNKit is an independent Java only implementation and includes a couple different interfaces, including one that is JavaHL compatible. If the use of the native libraries by JavaHL doesn't present a problem for you I'd recommend this since you'll have the benefit of using the same libraries as nearly every Subversion client.
If however your goal is to understand how Subversion implements the protocol on top of WebDAV and DeltaV then perhaps you want to just use a generic WebDAV and DeltaV client library to help. I'd recommend that you refer to these documents that describe how WebDAV and DeltaV are implemented within Subversion.
One thing you might want to understand is that as of Subversion 1.7 we support what we refer to as HTTPv2. HTTPv2 varies somewhat from the DeltaV standard in particular. Instead of using MKACTIVITY to start a transaction on the server we use a POST. Which has a body with a syntax something like this:
(create-txn)
or
( create-txn-with-props (PROPNAME PROPVAL [PROPNAME PROPVAL ...])
The older style which you must use with MKACTIVITY (and can use with the POST if you use create-txn instead of create-txn-with-props) is to use a PROPPATCH on the transaction or the working baseline URL.
The working baseline URL is used with MKACTIVITY and the transaction URL is used with the POST.
When using MKACTIVITY you have to use a PROPFIND on the root URL to get the version-controlled-configuration. Then do a CHECKOUT against the URL you received in response to that PROPFIND providing the activity-set href as the URL you used with MKACTIVITY. You'll get the working baseline URL back as the Location header from the CHECKOUT request. Which you can then use to issue a PROPPATCH to apply the revision properties.
When using POST, you get the transaction stub from the headers in the OPTIONS request response, the transaction name from the SVN-Txn-Name header in the response to the POST, and execute a PROPPATCH against the $transaction_stub/$transaction_name URL.
Probably the best ways to figure all this out is to setup a Subversion server and do some commits while running Subversion through a debugging proxy server such as Charles. You can force the traffic through the proxy on the svn command line with these options --config-option servers:global:http-proxy-port=8888 --config-option servers:global:http-proxy-host=127.0.0.1. If you want to see the old protocol you can include SVNAdvertiseV2Protocol off in your http configuration.
In order to support the broadest range of Subversion servers you need to implement the HTTPv1 protocol, which has more round trips and is more difficult to implement. If you want to only implement HTTPv2 you'll be limited to supporting Subversion servers newer than 1.7. In order to use HTTPv2 with maximum compatibility you'll have to detect the presence from the OPTIONS response.
As you can see it gets rather complicated so it's really not worth trying to write your own client if all you want to do is implement some basic functionality.
So you are trying to do a SVN commit using WebDAV via the SVNAutoversioning on directive?
http://svnbook.red-bean.com/en/1.7/svn.webdav.autoversioning.html
AFAIK, the spec does not allow you to provide a commit message and the server will always create one for you. Perhaps you want to look at the SVNKit library if you are trying to create SVN transactions via Java.
http://svnkit.com

$_POST undefined from remote server POST

I am writing a Drupal 7 module which is listening for HTTP POST messages to be sent by a 3rd party remote application. For testing I am sending messages using the Firefox Poster extension.
If I POST the message, the following code fails to place any value in my local vars (I get 'undefined index'):
$transId = urldecode($_POST['c2s_transaction_id']);
However, if I send the message using GET, the vars get populated fine with the following code:
$transId = urldecode($_REQUEST['c2s_transaction_id']);
This is true on both my local WAMP setup and on a shared hosting package.
I have never worked with HTTP POST messages before and have no idea where the problem might be. Could it be Drupal, the web server, or my code? Can anyone suggest how I might resolve this?
Many thanks,
Polly
Drupal removes the $_POST/$_GET in the system, just use $_REQUEST instead.