The song is somewhat different from Cad Goddeu, although it appears clear that it is based around tree knowledge. I am not certain whether Kipling derived this song from the Cad Goddeu. I am not sure why three trees oak ash and thorn are focussed upon in particular. Are these three trees all supposed to be related to midsummer?
Swearing this oath by oak, ash and thorn (o-a-th, perhaps?), goes way back and seems to have originated in a literary sense in the 9th-10th century with a bard whose name has come down to us as Glasgerion. About the bard’s name, there has been debate – some see it as a corruption of “Glas Gereint – “Blue Gereint” – whereas others have even seen a link to the Gwydion of The Mabinogi. It has been suggested that Kipling found this turn of phrase that he used in The Tree Song in the novel Westward Ho! (Charles Kingsley, 1855) in which Sir Richard Grenville also swears by the oak, ash and thorn; however, Kipling was most likely familiar with a good many traditional folk ballads of the time, of which Glasgerion is definitely one to consider.
“Glasgerryon swore a full great othe,
By oake and ashe and thorne,”
Whatever the reasons, the oak, ash and thorn are indeed trees with a great deal of folklore surrounding them in Britain and Ireland.